216k views
5 votes
1.16 LAB: Input and formatted output: House real estate summary Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two inputs, current price and last month's price (both integers). Then, output a summary listing the price, the change since last month, and the estimated monthly mortgage computed as (currentPrice * 0.051) / 12. End the last output with a newline. Ex: If the input is: 200000 210000 the output is: This house is $200000. The change is $−10000 since last month. The estimated monthly mortgage is $850. Note: Getting the precise spacing, punctuation, and newlines exactly right is a key point of this assignment. Such precision is an important part of programming.

User Cschuff
by
8.2k points

1 Answer

0 votes

# Constants

MONTHLY_RATE = 0.051 / 12

def main():

current_price = get_price_input("current")

last_month_price = get_price_input("last month's")

print_summary(current_price, last_month_price)

def get_price_input(name):

"""Get price input from user, convert to int"""

price = int(input(f"Enter {name} price: "))

return price

def print_summary(current_price, last_month_price):

"""Print formatted summary given current and last month's price"""

change = current_price - last_month_price

print(f"This house is ${current_price:,}.")

print(f"The change is ${change:,} since last month.")

print(f"The estimated monthly mortgage is ${estimate_mortgage(current_price):,.0f}.")

def estimate_mortgage(price):

"""Estimate monthly mortgage based on price"""

return price * MONTHLY_RATE

if __name__ == "__main__":

main()

User UltimoTG
by
7.9k points