Advertisement
kabads

Credit card bisection 2

Oct 14th, 2012
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. def payYear(startbalance, balance, minpayment, monthlyinterest, upper, lower):
  2.     while balance > 0.01:
  3.         month = 1
  4.         while month <13:
  5.             balance = (balance - minpayment) * ( 1 + monthlyinterest)
  6.             month +=1
  7.         if balance > 0.01:
  8.             balance = startbalance
  9.             upper = minpayment
  10.         elif balance < 0:
  11.             lower = minpayment
  12.         minpayment = (upper+lower)/2.0
  13.     return minpayment
  14.  
  15. balance = 320000
  16. startbalance = balance
  17. annualInterestRate = 0.2
  18. monthlyinterest = annualInterestRate/12
  19. lower = balance/12
  20. upper = (balance*(1+monthlyinterest)**12)/12
  21. minpayment = (upper+lower)/2.0
  22. ans = payYear(startbalance, balance, minpayment, monthlyinterest, upper, lower)
  23. print "minpayment is: " + str(round(ans, 2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement