Tips for those stuck on bisection for PSET 2. This should not be much different than your code for paying in $10 increments. First difference is lets say you had a variable min_month which you had set to 0 and incremented ten each time. In bi-section you create a variable for low bound and upper bound say pay_lower and pay_upper. You set these to what they should be, the formulas are given in the assignment. then you set min month to the average of those instead of increments of ten. Secondly, after each run through your loop, if you did not find the answer you make pay_lower or pay_upper
equal to min_month depending if you are too low or too high.
That is about all that should change, one thing of note is to make sure you use round before checking the too low/too high constrain or you might end up in an endless loop.
Some basic pseudocode would be set lower and upper bounds loop do calculate guess check guess if guess too high set high upper bound to guess if guess too low set lower bound to guess end loop Hope this helps someone.
And as always use lots of print statements to see where your logic may be going wrong.
Join our real-time social learning platform and learn together with your friends!