daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top