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

Hi everyone! I'm a bit confused about bisectioning in pset 1, problem 3. I understand how it chooses an upper and lower bound initially, and how it changes one of the two depending on an if statement. What I'm not sure about is what that if statement is in the context of the problem. Something like:: if minmonpay < x low = minmonpay else: high = minmonpay I can post what I have so far, but openstudy is being finnicky about what it wants to let me copy and paste. Thanks in advance!

OpenStudy (anonymous):

outBalance = float(raw_input('Enter the outstanding balance on your credit card: ')) annInt = float(raw_input('Enter the annual credit card interest rate as a decimal: ')) balance = outBalance low = outBalance/12.0 high = (outBalance * (1 + (annInt/12.0)) ** 12.0)/12.0 minMonPay = (high + low)/2 monthInt = (annInt/12.0) while balance > 0: month = 0 balance = outBalance if monthPay < x low = minMonPay else: high = minMonPay while balance > 0 and month < 12 month += 1 interest = monthInt + balance balance -= minMonPay balance += interest print 'Result' print 'Monthly payment to pay off debt in a year: ',round(minMonPay,2) print 'Number of months needed: ',month print 'Balance: ',round(balance,2) here's what I have so far

OpenStudy (e.mccormick):

For pasting, you could use pastebin or dpaste. That way when people copy the code and paste it they can have it work. If I try to copy what you wrote, it collapses down to one line. =/

OpenStudy (e.mccormick):

: missing on the if statement.

OpenStudy (e.mccormick):

And on the inner while loop.

OpenStudy (e.mccormick):

Where did "if monthPay < x" come from? monthPay is not defined. http://dpaste.com/1296423/

OpenStudy (anonymous):

@Avakuum please use a code pasting site: - http://dpaste.com - http://pastebin.com - https://gist.github.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.

OpenStudy (anonymous):

somtimes (a lot of times) it helps to right down in words what you are trying to do you define a searchspace using high and low you pick the middle item of that space and test it if it is just right stop and report the answer if it is too low you define a new search space that is the upper half of the previous space if it is too high you define a new search space that is the lower half of the previous space repeat

OpenStudy (anonymous):

looks like you might be missing one of the ifs

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!