SHARE
TWEET

CS-A1-Worksheet2

maincarry May 15th, 2016 16 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top