For the given answers to problem set 1, problem #2 I have 2 questions 1) while balance > 0: monthlyPayment += 10 balance = initialBalance numMonths = 0 while numMonths < 12 and balance > 0: In this block of code, why is it necessary to state that balance = initial balance? Also, why is it necessary to nest the second while statement? Arent we repeating ourselves by saying while balance >0 twice?
please use a code pasting site like: http://dpaste.com http://pastebin.com http://pastie.org https://gist.github.com be sure to select Python syntax highlighting
did you try to run it?? put some print statements in it to see what it is doing?
1. The reason you must assign balance = initialBalance is because you change the value of balance during each iteration of the inner loop. Since you are calculating the payment size necessary to pay off balance in a year you must start with the initial balance, each time you increment your payment amount. 2. You are not repeating yourself, the initial while condition ensures you do not execute the code if no balance exists.
Join our real-time social learning platform and learn together with your friends!