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

Problem Set #1 - Part B : Need help with setup Hey guys. I managed to solve part a of problem set 1 without much issue, but I'm having trouble really formulating a solution for the second question. I feel like I'm supposed to nest a "for-loop" to run through the months within a "while-loop" that increments the payment by 10 dollars each pass. My issue is that I'm having trouble breaking down the question in to separate parts, like calculating the new balance after each compounding period. Could anyone offer me some hints to get on the right track? I feel like I've hit a brick wall.

OpenStudy (anonymous):

you are correct in that you need to nest a for loop inside a while loop to solve the problem. the first step (as is the case for any mathematical problem) is to figure out what your variables are and then get them set up in python. one of them is the remaining balance and the other is an incrementing monthly payment (im guessing you have this figured out so far) you for loop should take the current monthly payment, and apply it to the balance based on the equation given in the problem set 12 times. after each month it should check if the balance has dropped below 0, if it has it should exit the for loop. after the for loop has run, the while loop should check if the remaining balance is less than 0. if it is not the while loop should reset the remaining balance to its original value and then increment the monthly payment by 10. these are the 3 chunks that you should break the problem down to. its just a matter of putting these words into lines of code

OpenStudy (anonymous):

Great response. Thanks so much! I think I know what I need to do now.

OpenStudy (anonymous):

Please i'm facing the same problem, can you help me? That's what I've done so far, but my program is stuck everytime in a loop: http://dpaste.com/1539469/

OpenStudy (anonymous):

wassi, sorry it took me so long to get back to you. when you enter the the while loop you have it check if balance<0. if it is not it enters the loop and from there you never update balance as you progress through the months. your loops just updates balanceA which isnt the variable your while loop is looking at.

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!