Advertisement
maincarry

CS-A1-Worksheet1

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