Skip to content

Instantly share code, notes, and snippets.

Created October 26, 2013 23:31
Show Gist options
  • Save anonymous/7175855 to your computer and use it in GitHub Desktop.
Save anonymous/7175855 to your computer and use it in GitHub Desktop.
balance = 5000
annualInterestRate = 0.04
monthlyIntr = annualInterestRate/12
lo = balance/12.00
hi = balance
guessed = False
while guessed == False:
guess = (lo+hi)/2
newbal = 0
for i in range(0,12):
newbal = (newbal-(guess))*(1+monthlyIntr)
if newbal > 0.12:
lo = guess
print "too low"
elif newbal < 0.12:
hi = guess
print "too high"
print guess
else:
guessed = True
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment