Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def bisect(balance, annualInterestRate):
- monthlyInterestRate = (annualInterestRate)/12
- lowerBound = (balance/12)
- upperBound = (balance *(1 + monthlyInterestRate)**12)/12
- newBalance = balance
- epsilon = 0.01
- monthpayment = (lowerBound + upperBound)/2.0
- while abs(monthpayment - newBalance)/2.0 >= epsilon:
- newBalance = balance
- for month in range(1,13):
- newBalance += (newBalance - monthpayment)*(1+(monthlyInterestRate))
- if newBalance > epsilon:
- lowerBound = monthpayment
- monthpayment = (lowerBound + upperBound)/2.0
- break
- else:
- upperBound = monthpayment
- monthpayment = (lowerBound + upperBound)/2.0
- break
- print ("Lowest payment: " + str(round(monthpayment,2)))
Add Comment
Please, Sign In to add comment