Advertisement
maincarry

CS-A1-Worksheet2

May 15th, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. '''
  2. Part 2: Loan
  3.  
  4. By Mark Wu 3217
  5. '''
  6.  
  7. def calculateRemainingLoanBalance(principal, annualInterestRate, duration, number_of_payments):
  8.     try:
  9.         n = duration * 12 # n is the total month
  10.         if annualInterestRate != 0:
  11.             r = annualInterestRate / 100 / 12 # r is the monthly interest rate
  12.         else:
  13.             r = principal / n
  14.         p = number_of_payments
  15.  
  16.         result = principal * ((1+r)**n - (1+r)**p) / ((1+r)**n - 1)
  17.         return result
  18.     except:
  19.         return 'Error'
  20.  
  21. # print(calculateRemainingLoanBalance(1000.0, 4.5, 5, 12))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement