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

Problem Set 1, Problem #2 The code: http://dpaste.com/798798/ The code is meant to request a credit balance and an annual interest rate (compounded monthly) from the user and then calculate the minimum payment necessary to eliminate the debt in 12 months or less, then print the value of the minimum payment, how many months it takes to pay off, and the final balance (<= 0). Revised: My code is problematic in that it doesn't return the correct response. In the body of the while loop, the for loop is phrased such that for EVERY month it checks the if/else condition (and adds 10 to the minpay if the balance isn't below zero). Is there an efficient way to phrase the for loop to only check the if/else conditions when it is at range(12)? Originally: "opens the console and then immediately closes it, with no print out. I've found a solution that works, but it bothers me that I don't understand why this code doesn't work." - turns out my problem was running it through Notepad++; it works fine launched through IDLE.

OpenStudy (anonymous):

pls use a code pasting site like http://dpaste.com or http://pastebin.com. http://dpaste.com/798722/ can you'walk thru' your code and explain what it is doing?

OpenStudy (anonymous):

(Thank you for the resource: http://dpaste.com/798798/ ) So I went back to the problem tonight in IDLE to get the text to paste to dpaste and now the code runs. It created the described behavior when it ran through Notepad++ the night previous, opening the console and closing it immediately, and still does so when I try to run it through Notepad++. Apparently my error was with the program, not my program! My code is still problematic in that it doesn't return the correct response. In the body of the while loop, the for loop is phrased such that for EVERY month it checks the if/else condition (and adds 10 to the minpay if the balance isn't below zero). Is there an efficient way to phrase the for loop to only check the if/else conditions when it is at range(12)?

OpenStudy (anonymous):

you have, i think, described the problem - you check the balance every month instead of after twelve months and you seem to understand that it is because your for loop is 'prhased' incorrectly. you need to move the test outside of the for loop - you need to change its indentation http://docs.python.org/reference/compound_stmts.html when you execute via notepad++ it is just opening a dos window running it then the dos window closes automatically. if you want it to stay open, you have to open a dos window, start a python shell in the window and run the program or just run the program from the dos prompt. hmmm not sure that is completely correct, i haven't done it in a long time. http://docs.python.org/faq/windows.html

OpenStudy (anonymous):

I believe your If Else statement is the problem. I wonder if you can step through a problem in Python because that would certainly help you troubleshoot this problem. Lets do it the old fashioned way. You hit your for loop and do the first monthly payment calculation. The next thing the program will do is check the If Else statement. The problem is you aren't cycling through a years worth of payments to see if you will pay off the debt. In fact the very next thing the program will do is say For condition not met so I will do Else which automatically increases minpay. The program will then go on to calculate month 2 and so on compounding the issue.

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!