Advertisement
ss1030

bisection_min_payment

Jun 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. balance = 320000
  2. annualInterestRate = 0.2
  3. monthlyInterestRate = annualInterestRate/12
  4. newbalance = balance
  5. epsilon = 0.01
  6. low = 0
  7. high = balance
  8. ans = (high + low)/2.0
  9.  
  10. while abs(high - low) > epsilon:
  11.     newbalance = balance
  12.     for n in range(12):
  13.         unpaid = newbalance - ans
  14.         newbalance = unpaid + (unpaid * monthlyInterestRate)
  15.     if newbalance > 0:
  16.         low = ans
  17.     else:
  18.         high = ans
  19.     ans = (high + low)/2.0
  20. print("Lowest payment: " + str(round(ans, 2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement