Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Assignment Write a program called mortgageCalculator.py. Create a mortgag

ID: 3812021 • Letter: P

Question

Python Assignment

Write a program called mortgageCalculator.py. Create a mortgage calculator. It should calculate

mortgage payments and total mortgage cost.

Users will enter the following:

• The amount of money borrowed (principal)

• The duration of the loan in years (years)

• The annual percentage rate for the loan (apr)

• The number of payments made so far (paidPayments)

The program will calculate:

• Total number of payments (totalPayments)

• Monthly payment amount (payment)

• Total cost for the loan (totalCost)

• Total interest (totalInterest)

• Outstanding principal (outstanding)

• Amount paid so far (paid)

Explanation / Answer

Code:

#!/usr/bin/python
#inputs form user
principal = int(input("Enter the amount of money borrowed: "))
loan_years = int(input("Duration of loan (in years): "))
total_payments = loan_years * 12 # calculating total payments to be made
interest_year = float(input("Annual Rate of Interest: "))
interest_month = interest_year / (12 * 100) #calculating rate of interest per month
paid_payments = int(input("Number of monthly payments made: "))
monthly_payments = principal * (interest_month / (1 - (1 + interest_month) ** -total_payments)) #calculating amount of payment to be made monthly
total_cost = monthly_payments * total_payments #calculating total cost incurred
total_interest = total_cost - principal #calculating total interest to be paid
paid = monthly_payments * paid_payments #calculating amount paid so far
outstanding = principal
if paid_payments > 0:
for i in range(paid_payments): #calculating outstanding. can be modified to calculate amoritzation schedule
monthly_interest_paid = principal * interest_month
monthly_principal_paid = monthly_payments - monthly_interest_paid
outstanding = outstanding - monthly_principal_paid
balance = principal - monthly_principal_paid
principal = balance
#printing output
print("Total number of payments: $",total_payments)
print("Monthly payment amount: %.2f"%(monthly_payments))
print("Total cost for the loan: %.2f"%(total_cost))
print("Total interest: %.2f"%(total_interest))
print("Outstanding principal: %.2f"%(outstanding))
print("Amount paid so far: %.2f"%(paid))