Bisection Search for Minimum Payment (Python) - answer is too large -


doing bisection search determining minimum monthly payment pay off credit card balance in 1 year. result few hundred large, , fails print in mitx: 6.00.1x online submission module (always prints 0.00). can please offer suggestions?

code:

balance = 999999 annualinterestrate = 0.18 interest = annualinterestrate / 12.0 lower = balance / 12.0 upper = (balance * (1+ interest)**12) / 12.0 guess = (upper + lower) / 2  remainder = balance newbalance = 0  epsilon = 0.00000001  while (newbalance > epsilon):     guess = (upper + lower) / 2     in range (0,12):         newbalance = remainder - guess         remainder -= guess         month_interest = newbalance * interest         remainder = newbalance + month_interest          if newbalance < 0:             upper = guess             newbalance = balance         elif newbalance > epsilon:             lower = guess             newbalance = balance  print "lowest payment: %.2f" %guess  

the problem is, set newbalance = 0. while-condition newbalance > epsilon never true , jump right print statement. set newbalance 1 or whatever.


Comments