Guest User

Untitled

a guest
Jan 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. def bisect(balance, annualInterestRate):
  2.  
  3.     monthlyInterestRate = (annualInterestRate)/12
  4.     lowerBound = (balance/12)
  5.     upperBound = (balance *(1 + monthlyInterestRate)**12)/12
  6.     newBalance = balance
  7.     epsilon = 0.01
  8.     monthpayment = (lowerBound + upperBound)/2.0
  9.  
  10.     while abs(monthpayment - newBalance)/2.0 >= epsilon:
  11.  
  12.         newBalance = balance
  13.  
  14.         for month in range(1,13):    
  15.             newBalance += (newBalance - monthpayment)*(1+(monthlyInterestRate))
  16.  
  17.         if  newBalance > epsilon:
  18.             lowerBound = monthpayment
  19.             monthpayment = (lowerBound + upperBound)/2.0
  20.             break
  21.         else:
  22.             upperBound = monthpayment
  23.             monthpayment = (lowerBound + upperBound)/2.0
  24.             break  
  25.     print ("Lowest payment: " + str(round(monthpayment,2)))
Add Comment
Please, Sign In to add comment