Skip to content

Instantly share code, notes, and snippets.

@lfcunha
Created October 11, 2012 23:01
Show Gist options
  • Save lfcunha/3876133 to your computer and use it in GitHub Desktop.
Save lfcunha/3876133 to your computer and use it in GitHub Desktop.
2.3
import math
balance=10050000
annualInterestRate=0.2
monthly=annualInterestRate / 12
lo=balance/12
hi=balance+(balance * annualInterestRate)
error=10000
while(error>0.01):
b=balance
c=(lo+hi)/2
print "C: ", round(c,2)
for i in range(1,13):
b=(b-c)*(1+monthly)
error=math.sqrt(math.pow((b-0), 2))
if b>0:
lo=c
c=(lo+hi)/2
elif b<0:
hi=c
c=(lo+hi)/2
b=(b-c)*(1+annualInterestRate/12)
print "Lowest Payment:", round(c, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment