Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calcPay(newBal, mIR, guess):
- for x in range(12):
- newInt = ((newBal - guess) * mIR)
- newBal = (newBal - guess + newInt)
- return newBal
- def othermain(balance, annualInterestRate):
- epsilon = 0.01
- mIR = annualInterestRate /12.0
- low = balance/12
- high = round(((balance*(1+mIR)**12)/12),2)
- guess = round(((high+low)/2.0),2)
- ans = round(calcPay(balance,mIR,guess),2)
- print('')
- print('lo: '+str(low)+' hi: '+str(high))
- print('')
- print('guess: ' + str(guess) + ' ans: ' + str(ans))
- while abs(balance -(guess*12)) <= epsilon:
- newbal =(ans*12)-balance
- print('')
- print('ans*12-bal: ' + str(newbal))
- if newbal < epsilon:
- high = guess
- else:
- low = guess
- print('')
- print('lo: '+str(low)+' hi: '+str(high))
- guess = round(((high+low)/2.0),2)
- ans = round(calcPay(balance,mIR, guess),2)
- print('')
- print('guess: '+str(guess)+' ans: '+str(ans))
- print('lowest payment: ' +str(guess))
- othermain(320000,0.2)
- othermain(999999,0.18)
Add Comment
Please, Sign In to add comment