Problem set 1b is tripping me up. I absolutely hate compounding interest questions. Ugh... I have the solution written in words, but I can't figure out how to write a loop that will check the two conditions and reloop from the start after adding the $10 to the payment. I'm sure this is a very simple program, I'm just overlooking something. This is my idea in words: 1- try pmt (starting at $10) for 12 months less. 2- test, if balance is > 0, reset month and balance 3- try pmt = $10 for 12 months or less. 4- test again
My code so far... balance = float(raw_input("Outstanding Balance: ")) annualInterest = float(raw_input("Annual Interest Rate: ")) monthlyInterest = annualInterest / 12 minMonthlyPmt = 10.0 month = 1 newBalance = balance while newBalance > 0 or month < 12: newBalance = newBalance * (1 + monthlyInterest) - minMonthlyPmt month = month + 1 if month > 12: month = 1 newBalance = balance minMonthlyPmt =+ 10 else: print "Monthly payment to pay off debt in 1 year: $" + str(round (minMonthlyPmt,2)) print "Number of months needed: " + str(month) print "Balance: $" + str(round (balance, 2))
Starting month = 1, you probably want in your while statement month <= 12. The fact that statement #4 says test again, means that all of the code after initialization is in a loop. It may help you to put your four statements into your program as comments, and write your code to them. If they're not specific enough, flesh them out.
Changed the code to this: balance = float(raw_input("Outstanding Balance: ")) annualInterest = float(raw_input("Annual Interest Rate: ")) monthlyInterest = annualInterest / 12 minMonthlyPmt = 10.0 month = 1 newBalance = balance while newBalance > 0 or month < 12: newBalance = newBalance * (1 + monthlyInterest) - minMonthlyPmt month = month + 1 if month > 12: month = 1 newBalance = balance minMonthlyPmt += 10 I seems to work, but I'm getting a different answer for the second test case. Why did the example answer stop at $2970 for a payment, while mine stopped at $3210? Both answers pay off the bill in 12 months, but mine pays less interest over time and ends with a smaller neg balance. Does this make a difference? Thanks.
Now I'm really curious. The example answer is the least amount you can pay to pay it off in 12 months and my answer is the most you can pay to pay off in 12 months. How did I do that?
Any clues? Anyone?
Join our real-time social learning platform and learn together with your friends!