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

Hi, I am working on PS1 #3 ... I just cant produce the sample case in the instructions (its close but its not it

OpenStudy (anonymous):

My code produce roughly the same result as the sample solution offers... it doesnt match the instruction though... balance = float(raw_input('Enter the outstanding balance on your credit card: ')) interestRate = float(raw_input('Enter the annual credit card interest rate as a decimal: ')) newBalance = balance lowerBound = balance / 12.0 upperBound = balance * (1 + interestRate / 12) ** 12.0 / 12.0 while abs(lowerBound - upperBound) > 0.001 : monthlyPayment = (lowerBound + upperBound) / 2 newBalance = balance for monthsNeeded in range(1,13): newBalance = newBalance * (1 + interestRate / 12.0) - monthlyPayment if newBalance <= 0: break if newBalance >= 0: lowerBound = monthlyPayment else: upperBound = monthlyPayment print 'RESULT' print 'Monthly payment to pay off debt in 1 year: ' + str(round(monthlyPayment,2)) print 'Number of months needed: ' + str(monthsNeeded) print 'Balance: ' + str(round(newBalance,2)) thanks in advance

OpenStudy (anonymous):

Hey! Like @bwCA told me a couple of days ago, print statements are a good way to debug your code and see how the problem is computed http://dpaste.com/767081/ What do you mean it doesn't do it like in the instructions? do you mean you get another result than the sample solution? also, you should use a pasting site to refer to your code, like dpaste.com (i was told a few days ago:)

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!