Reputation: 25
The code is returning extremely low values for a mortgage payment.
I expected something like 18,000 (assuming no tax, no insurance, etc.), So what values do I need to change to get that number? Is their something wrong with the way I code? And yes, I did Google. Just some afternoon project to get back into coding. Thanks!
p = float(input("What is your mortgage principal?"))
r = float(input("What's your interest rate?"))
t = int(input("How long is your mortage gonna last?"))
n = 12
finalresult = p * (1 + (r/t))**(n * t)
print("This is how much you will be paying over one year!", finalresult)
Sample input/output:
What is your mortgage principle?300000
What's your interest rate?3.5
How long is your mortage gonna last?15
This is how much you will be paying over one year! 7.44056195468128e+21
Process finished with exit code 0
Upvotes: 1
Views: 78
Reputation: 155438
The interest rate you're providing is a percentage, which needs to be divided by 100 to produce a mathematically useful value. If you'd entered 0.035
you'd get a reasonable figure of 456365.140385318
. If you expect users to provide the percentage (reasonable), then perform the division for them, and the rest of the math will work out:
r = float(input("What's your interest rate (as a percentage, e.g. 3.5)?")) / 100
As noted in the comments, the calculation of finalresult
should be using r/n
, not r/t
; you're dividing the rate up over the months of the year, not over the years of the mortgage after all. For a 15 year mortgage, the error isn't as obvious as the off-by-100x rate issue, but it's still pretty significant (it underestimates the total paid by ~$50K for your example case).
Upvotes: 2