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

I probably missed it in the lecture, but what's the round function? (for question 1 on pset 1) thnx:)

OpenStudy (anonymous):

The round() function is used to 'round off' a floating point number. for example say : round(1.7543754,2) would round off the result to two decimal places In this case 1.75. Note that this is different from truncating the digits . round(1.7999999999,1) would be 1.8 not 1.7

OpenStudy (anonymous):

thanks! then I have (at least) a couple more principal problems. here's my sort of first shot: x = float(raw_input('Enter the outstanding balance on your credit card: ')) y = float(raw_input('Enter the annual credit card interest rate as a decimal: ')) z = float(raw_input('Enter the minimum monthly payment rate as a decimal: ')) a = (z*x) b = (a-x*y/12.0) for i in range(1, 13): print ('Month:' + int(i')) print ('minimum monthly payment: ' + a) print ('principle paid: ' + b) round(x, 2) round(a, 2) round(b, 2) the first thing i need to understand, i think, is how to iterate the algorithm and print the result of each month... any hints?

OpenStudy (anonymous):

sorry, here's the link... http://dpaste.com/766397/ getting better...

OpenStudy (anonymous):

@ajitnath i'm trying with a while loop instead, (with i += 1) but i think i'm completely wrong from the very beginning:)

OpenStudy (anonymous):

Yeah kinda :) there are couple of things here :- 1. Instead of rounding off at the very end , you should round off the the result after every calculation.Say a=round(z*x,2) and b=round((a-x*y/12.0),2) 2. You should put the calculations inside the loop that way you calculate the balance,interest incurred and principle paid for every month as the principle amount decreases take a look at this code with the while loop. If you don't get anything just ask :) http://dpaste.com/766443/

OpenStudy (anonymous):

actually i was way less far out than i thought:) so IDLE computes new values simply because it necessarily changes with every "i", or because you put i += 1 at the end? (as opposed to when defining the loop) i get syntax error for the print 'Balance'... why?? thx again!

OpenStudy (anonymous):

and here's the script http://dpaste.com/766513/

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!