pythonedx

CS1301xl Computing in Python I practice exam mortgage problem’s formula may be somehow incorrect?


I’d like to know whether this is the formula problem or my problem.

I’ve looked up various formulas online. This is edx’s formula Cost * Number of Months * Monthly Rate / 1 - ((1 + Monthly Rate) ** Number of Months)

cost = 150000
rate = 0.0415 
years = 15
rate = rate / 12 
years = years * 12
house_value = cost * years * rate 
house_value2 = (1 + rate) ** years
house_value = house_value / house_value2
house_value = round(house_value, 2)
print("The total cost of the house will be $" + str(house_value))

It should print “The total cost of the house will be $201751.36” but it prints “The total cost of the house will be $50158.98”


Solution

  • I have now solved this. This is the edit.

    cost = 150000
    rate = 0.0415 
    years = 15
    house_value = cost * (years * 12) * (rate / 12)
    house_value2 = 1 - (1 + (rate / 12)) ** -years
    house_value = house_value / house_value2
    house_value = round(house_value, 2)
    print("The total cost of the house will be $" + str(house_value))
    

    I have added a negative sign to the years.