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

Hi! I'm stuck on the third problem of PS1. I've gotten to where the code returns answers, but they don't match the answers given in the assignment PDF. Does anyone have suggestions? b=float(raw_input('What is your balance? ')) i-float(raw_input('What is your interest rate?')) p=0.01 balance=b low=b/12.0 high=(b*(1+(i/12.0))**12.0)/12.0 while True: for month in range (1,13): balance=balance-guess balance=balance+((i/12,0)*balance) if balance>0 and balance>-p: low=guess balance=b elif balance<0 and balance>-p: high=guess balance=b

OpenStudy (anonymous):

(sorry, got cut off) else: print ('Result:') print ('Lowest payment possible: ' + str(round(guess,2))) break

OpenStudy (turingtest):

if p is your margin of error due to floating point imprecision your condition should be if balance < p and balance > -p: ##code or more succinctly: if abs(balance) < p: ##code the way you wrote your first condition is redundant: " if balance>0 and balance>-p:" if balance is greater than 0, it must also be greater than -p. I would also recommend making your margin of error smaller than what you eventually round to, i.e. p=1e-6 would be more precise

OpenStudy (anonymous):

So right now I have for month in range(1,13): balance=balance-guess balance=balance+((i/12.0)*balance) if balance>0: low=guess balance=b elif balance<p and balance>-p: high=guess balance=b else: print('Lowest payment: ' + str(round(guess,2))) break I'm still not sure how to fix it.

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!