From 83362aabfc0b0b503430206da437c9dcabdee7b5 Mon Sep 17 00:00:00 2001 From: StephenAjayi Date: Thu, 19 Nov 2015 15:35:21 -0800 Subject: [PATCH] Update Module4MortgageCalculatorChallengeSolution.py These videos are great but this challenge gave me a few problems because the monthly payments seemed astronomical. After some tinkering around i realized a couple things in the given info were inaccurate: 1. The interest amount is compounded monthly, so if a user entered .05 as as their interest rate would actually be paying 5% interest per month, 60% interest a year and 600% interest on a 10 year loan. I made the change to line 17 to reflect interest properly. 2 For the monthly mortgage calculation, numberOfPayments should be an exponent on both sides of the equation , rather than being multiplied. I made this change to line 23-24 as well. --- Solutions/Module4MortgageCalculatorChallengeSolution.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Solutions/Module4MortgageCalculatorChallengeSolution.py b/Solutions/Module4MortgageCalculatorChallengeSolution.py index ddb9c28..d069481 100644 --- a/Solutions/Module4MortgageCalculatorChallengeSolution.py +++ b/Solutions/Module4MortgageCalculatorChallengeSolution.py @@ -14,14 +14,14 @@ #Convert the strings into floating numbers so we can use them in teh formula loanDurationInYears = float(strLoanDurationInYears) loanAmount = float(strLoanAmount) -interestRate = float(strInterestRate) +interestRate = float(strInterestRate)/12 #Since payments are once per month, number of payments is number of years for the loan * 12 numberOfPayments = loanDurationInYears*12 #Calculate the monthly payment based on the formula -monthlyPayment = loanAmount * interestRate * (1+ interestRate) * numberOfPayments \ - / ((1 + interestRate) * numberOfPayments -1) +monthlyPayment = loanAmount * interestRate * (1 + interestRate)** numberOfPayments \ +/((1 + interestRate) ** numberOfPayments - 1) #provide the result to the user print("Your monthly payment will be " + str(monthlyPayment))