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.045) / 12.

Respuesta :

Answer:

integer currentPrice

integer lastMonthPrice

integer changeLastMonth

float mortagage

//Reading input

currentPrice = Get next input

lastMonthPrice = Get next input

//Calculating price change

changeLastMonth = currentPrice - lastMonthPrice

//Calculating mortagage

mortagage = (currentPrice * 0.045) / 12

//Printing output

Put "This house is $" to output

Put currentPrice to output

Put "\nThe change is $" to output

Put changeLastMonth to output

Put " since last month." to output

Put "\nThe estimated monthly mortgage is $" to output

Put mortagage to output

Answer:

  1. current_price = int(input("Enter current price: "))
  2. l_price = int(input("Enter last month price: "))
  3. for i in range(1, 13):
  4.    print("Current price: $" + str(current_price) + ",  Last month price: $" + str(l_price))  
  5.    l_price = current_price
  6.    current_price += (current_price * 0.045) / 12

Explanation:

The solution code is written in Python 3.

Firstly, get user input for current price and last month price (Line 1 -2).

Create a for loop to traverse through the number from 1 to 12. In the loop, print the current price and last month price (Line 5). Before proceeding to the next round of loop, set the current_price to l_price and then apply the given formula to recalculate the estimated monthly mortgage and assign it to current_price (Line 6-7).