Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 13 Online
OpenStudy (anonymous):

I have an issue on problem set 1b from 2011. I'm calculating the correct answer for the monthly payment to pay off the debt in a year, but for some reason I'm having trouble with the incrementation. It keeps saying it takes 13 months, when it really is only taking 12, but I can't get it to display correctly. Can someone take a look at my code? I apologize for all the print statements....I've been trying to debug it for the last little while.... http://codepad.org/asro6OuO

OpenStudy (anonymous):

The weird thing is, for test case 1, everything checks out fine. For test case 2, it says it takes 13 months....

OpenStudy (anonymous):

your code looks waaaay different than mine.. I got mine to work but I used a while loop with a for loop.. #B: balance // iniB: initial balance // and mo: month while B > 0: B = iniB mmp = mmp + 10 for mo in range(1, 13): B = B * (1 + mir) - mmp B = round(B, 2) if B <= 0: break hope this helps.. im stuck on #3. let me know if you get stuck :)

OpenStudy (anonymous):

ooops everything after the for loop is indented.. and break indented x2

OpenStudy (anonymous):

I dont think your code is right. this is what i get when i run your program >>> Enter the outstanding balance: 1200 Enter the annual interest rate: .18 1 2930.0 -1712.0 RESULT Monthly payment to pay off debt in 1 year: 2930.0 Number of months needed: 2 Balance: -1712.0 >>>

OpenStudy (anonymous):

- monthly payment = 0 - while balance is > 0 then * reset the balance to original balance * increment the monthly payment - simulate 12 months with that payment: each month; * add monthly interest * subtract monthly payment

OpenStudy (anonymous):

You are starting with month 1 and then increasing by one each time through the while loop, which means you will always have a result one month higher than you should. You should be starting with month (in your code, i)= 0. Consider a test case where you pay back all of the principle plus interest in one month: You start with month = 1, and go into your while loop, updatedBalance = 0 print str(month) ( this will print 1) month = month + 1 (your month is now 2, which you don't want, you have payed in full) Now you restart the while loop, and go to the elif statement. Of course, you have the wrong number of months.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!