MIT 6.00 Intro Computer Science (OCW)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
Probably, without seeing any code, just assign the balance after month 1 to whatever variable was the starting balance for month 1 and let it run.
use a loop, modify the balance variable in the loop, on the next iteration (month) it will be the balance for the next month
Thanks for the replies! I thought I tried to create a loop with the following code, but it just gives me the same values I get for Month 1 for months2-12. Any clue where I go wrong? Code: #Gets initial values for credit variables from user input bal = float(raw_input('Enter the outstanding balance on your credit card: ')) apr = float(raw_input('Enter the annual interest rate as a decimal: ')) mpr = float(raw_input('Enter the minimum monthly payment rate as a decimal: ')) #Basic equations that use input values to return the new balance minpay = mpr*bal intpaid = apr/12 *bal prinpaid = minpay - intpaid newbalance = bal - prinpaid m = 1 for m in range(1,13): print 'Month: ', m print 'Minimum monthly payment: ', minpay print 'Principle paid: ', prinpaid print 'Remaining balance: ', newbalance bal = newbalance
That last bit should read, bal = newbalance, flush under the last print command...
please use a code pasting site: - http://dpaste.com - http://pastebin.com - http://www.repl.it/ - http://pastie.org - http://codepad.org - http://ideone.com paste your code there and post the link here. select Python syntax highlighting when u paste.
Oh ok, sorry about that!
in your loop, what kind of statements are you executing? Are there any statements in the loop that modify bal or newbalance?
when you think about this problem, what happens over and over again each month?
all of the equations are calculated each month (save for 2), because they all involve a quantity that is changing from month to month--the balance. But I thought that if I wrote bal = newbalance, the next time it runs the loop for month two, it should give me the write result, since the bal for month 2 will now be factored into the variables I ask it to output, if that makes sense.
... i don't see any calculations in the for loop, just print statements
Ok, so if put the calculations in the loop and THEN put bal=newbalance, that will solve my problem?
Thanks for taking the time to reply, btw...
the calcs need to be in the loop. does mpr change every month or is it constant? "... THEN put bal=newbalance, ... " you could just use bal = bal - prinpaid
mpr is constant... yeah, since i just started this stuff yesterday, i keep wanting to create a new variable every time that variable changes... i forget that bal = bal - prinpaid is a possibility
Thanks so much for your help... i think I can get it to work with the info you gave me!
Yay! it worked...
If you're still here, how do I get python to show the return values with two and only decimal places (it's a float return)?