Skip to content

Instantly share code, notes, and snippets.

@Zoha131
Last active September 22, 2016 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zoha131/4eac11178c7634cb57f3b67ffdaea488 to your computer and use it in GitHub Desktop.
Save Zoha131/4eac11178c7634cb57f3b67ffdaea488 to your computer and use it in GitHub Desktop.
MIT- 6.00.1x || week 2 || pset-2 || problem-3
annualInterestRate = 0.2
balance = 320000
# variable for Monthly Interest rate
mir = annualInterestRate / 12.0
pb = balance
#lower bound
lwb = balance /12
#upper bound
upb = (balance*((1+mir)**12))/12.0
#middle bound
mmp = (lwb+upb)/2
# test function
def test():
# minimum monthly payment
global mmp
mmp = (lwb+upb)/2
global pb
pb = balance
for n in range(12):
# monthly unpaid balance
mup = pb - mmp
pb = mup + (mup * mir)
while True:
if pb <= 0 and abs(pb) < mmp:
break
elif pb < mmp:
lwb = mmp
test()
elif pb > mmp:
upb = mmp
test()
print("Lowest Payment: " + str(round(mmp, 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment