Guest User

Untitled

a guest
Jan 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1.  
  2. def calcPay(newBal, mIR, guess):
  3.     for x in range(12):
  4.         newInt = ((newBal - guess) * mIR)
  5.         newBal = (newBal - guess + newInt)
  6.     return newBal
  7.  
  8. def othermain(balance, annualInterestRate):
  9.     epsilon = 0.01
  10.     mIR = annualInterestRate /12.0
  11.     low = balance/12
  12.     high = round(((balance*(1+mIR)**12)/12),2)
  13.     guess = round(((high+low)/2.0),2)
  14.     ans = round(calcPay(balance,mIR,guess),2)
  15.    
  16.     print('')
  17.     print('lo: '+str(low)+' hi: '+str(high))
  18.     print('')
  19.     print('guess: ' + str(guess) + ' ans: ' + str(ans))
  20.  
  21.     while abs(balance -(guess*12)) <= epsilon:
  22.  
  23.         newbal =(ans*12)-balance
  24.  
  25.         print('')
  26.         print('ans*12-bal: ' + str(newbal))
  27.                            
  28.         if newbal < epsilon:
  29.             high = guess
  30.         else:
  31.             low = guess
  32.  
  33.         print('')
  34.         print('lo: '+str(low)+' hi: '+str(high))
  35.  
  36.         guess = round(((high+low)/2.0),2)
  37.         ans = round(calcPay(balance,mIR, guess),2)
  38.         print('')
  39.         print('guess: '+str(guess)+' ans: '+str(ans))
  40.     print('lowest payment: ' +str(guess))
  41. othermain(320000,0.2)
  42. othermain(999999,0.18)
Add Comment
Please, Sign In to add comment