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

Hi! I'm working on problem set 1, problem 1 and I got the code down for the loop for 12 months but how do I print out the final amount due after 12 months?

OpenStudy (anonymous):

Place a print statement on the outside of your loop, telling it to print the variable that you have set that value to. If that doesn't help, try attaching your code to your message, and I'll take a look at it.

OpenStudy (anonymous):

Helps if you attach your code with your question.

OpenStudy (anonymous):

print("Final Balance" + str(round(balance,2)))

OpenStudy (anonymous):

The problem I am having is that when I run my code, it prints out my original balance instead of the final balance after 12 months... heres my code. thank you for all your help!! I really really appreciate it!!

OpenStudy (anonymous):

You are not actually assigning new values to your variables; your "for month in range(1,13)" block prints the same value for every month. There needs to be some sort of operation that's iterated in that loop. "a = x*z b = y/12*x c = a-b d = x-c" these values: initial balance, min monthly payment, principal paid, and final balance, respectively, should change every time the loop goes around (per month) Your final answer should come out correct if those operations are iterated for each month. P.S. you seem to be using Python ver. 2.7.3 'print' is a keyword and not a function and therefore parentheses are not needed.

OpenStudy (anonymous):

i still dont understand how to reiterate it for every month though. how do I put that in the operation loop?

OpenStudy (anonymous):

does anyone have the code, because I think that would help to look at!! thanks!

OpenStudy (anonymous):

I've attached my code for ps1 problem 1. I didn't put any comments in, because I was just running through it quickly, so hopefully you can follow it.

OpenStudy (anonymous):

Hi!, Here's my version: http://pastebin.com/KnqjrhXb Notice that the final print statements will execute after the for loop finishes.

OpenStudy (anonymous):

thanks so much!!! I really appreciate it. I understand now thank you :)

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!