Skip to content

Instantly share code, notes, and snippets.

@adriendumont
Last active December 27, 2015 04:38
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 adriendumont/7267852 to your computer and use it in GitHub Desktop.
Save adriendumont/7267852 to your computer and use it in GitHub Desktop.
# part 1
tp = 0 #total paid
ub = balance # updated balance
for i in range(1, 13):
print("Month: " + str(i))
mmp = ub * monthlyPaymentRate
tp += mmp
up = ub-mmp
ub = up*(1+annualInterestRate/12)
print("Minimum monthly payment: " + str(round(mmp,2)))
print("Remaining balance: " + str(round(ub, 2)))
print("Total paid: " + str(round(tp, 2)))
print("Remaining balance: " + str(round(ub, 2)))
# part 2
mir = annualInterestRate/12 # monthly interest rate
mp = 10 # monthly payment
ub = balance
while ub>0:
ub = balance
for i in range(1, 13):
mub = ub - mp
ub = mub* (1+mir)
mp+=10
print ("Lowest Payment: " + str(mp-10))
# part 3
mir = annualInterestRate/12 # monthly interest rate
mplb = balance/12
mpub = (balance*(1+mir)**12)/12
def yb(mir, ub, mp): # balance after a year
for i in range(1, 13):
mub = ub - mp
ub = mub* (1+mir)
return ub
ub = balance
for i in range(100):
mid = (mplb + mpub)/2
if yb(mir, ub, mid)>0:
mplb = mid
else:
mpub = mid
print("Lowest Payment: " + str(round(mid, 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment