In: Computer Science
Using Anaconda Python, program the following:
Overview
In this program you will develop an application that will display an amortization schedule. The word "amortize" means to "To write off gradually and systematically a given amount of money within a specific number of time periods." It will show, for each month of the loan, how much of your monthly loan payment is being applied towards interest costs, and how much is actually being applied to reduce the outstanding balance (principal) of your loan.
The Problem
Your application should prompt the user to enter a number of amount of the loan, the annual interest rate, and the duration of the loan in months and then calculates the sum total of all payments over the life of the loan, the total interest paid over the life of the loan, and finally the total interest paid as a percentage of the principal (i.e, original loan amount). Your program requires a loop to make calculations for each payment, which means that the loop must run until all payments have been made. You first determine the payment amount, and then for every payment you determine the interest paid, the principal paid, and the principal balance remaining.
To Get You Started
The following tables provide a description of the variables used. Note that the variable names chosen clearly describe the purpose of the variables.
Input Variables:
Variable Name | Purpose |
---|---|
loan_amount | Total amount borrowed |
interest_rate | Annual interest rate expressed as a percentage |
num_payments | Loan duration expressed in months |
Intermediate Calculation Variables:
interest_per_year | Decimal interest per year |
interest_per_payment | Decimal interest per payment |
factor | Intermediate variable |
payment_amount | Amount of each monthly payment |
total_payed_on_loan | Total amount payed on loan |
total_interest_paid | Total interest payed on loan |
interest_as_percent_loan_amount | Total interest as a percentage of original loan amount |
The following variables will need to be calculated within your loop:
monthly_interest | The amount of interest paid in a given month |
monthly_principal | The amount of principal paid in a given month |
loan_amount (formerly loan_balance) | The new amount after the principal has been paid |
You will find the following formulas helpful (necessary?):
interest_per_year = interest_rate / 100.0
interest_per_payment = interest_per_year / 12
factor = (1 – ((1 + interest_per_payment) ** (-num_payments))) / interest_per_payment
payment_amount = loan_amount / factor
total_paid_on_loan = payment_amount * num_payments
total_interest_paid = total_paid_on_loan – loan_amount
interest_as_percent_loan_amount = (total_interest_paid / loan_amount) * 100
Within your loop you will need the following formulas:
monthly_interest = interest_per_payment * loan_amount
monthly_principal = payment_amount – monthly_interest
loan_amount = loan_amount – monthly_principal
Output
Your program should display the monthly payment, the total amount paid on the loan, the total interest paid on the loan, and the total interest as a percentage of the original loan amount. Then, for each loan payment, display the month, payment amount, interest paid, principal paid, and the loan balance. Please see sample output on the following pages.
Deliverables
Include a markup cell at the top of your program. Within the markup cell, list your name, course and section, assignment number, and date. Use whitespace effectively to make your code easier to read. Follow the recommended naming conventions for variables.
code: # Your Name: # Course: # Section: # Assignment number: # Date: # amount for which loan is taken loan_amount = float(input("Enter loan: ")) # Annual interest rate interest_rate = float(input("Enter annual interest rate: ")) # total number of months for which the loan is taken num_payments = int(input("Enter loan duration expressed in months: ")) print() # calculating annual interest rate interest_per_year = interest_rate / 100 # calculating monthly interest rate interest_per_payment = interest_per_year / 12 # calculating annual amount paid on loan and total interest paid on loan factor = (1 - ((1 + interest_per_payment) ** (- num_payments))) / interest_per_payment payment_amount = loan_amount / factor # monthly total_paid_on_loan = payment_amount * num_payments total_interest_paid = total_paid_on_loan - loan_amount # calculating total interest as percent of the loan amount interest_as_percent_loan_amount = (total_interest_paid / loan_amount) * 100 print("Original loan amount taken: %f" % loan_amount) print("Total amount paid on the loan: %f" % total_paid_on_loan) print("Total interest paid on the loan: %f" % total_interest_paid) print("Total interest as a percentage of the original loan amount: %f" % interest_as_percent_loan_amount) print() # for loop, it will run number of months time for i in range(1, num_payments + 1): monthly_interest = interest_per_payment * loan_amount monthly_principal = payment_amount - monthly_interest loan_amount = loan_amount - monthly_principal print("Month: %d" % i) print("Monthly payment: %f" % (monthly_principal + monthly_interest)) print("Monthly interest paid: %f" % monthly_interest) print("Loan balance: %f" % loan_amount) print()
Screenshots:
code:
output:
1)
2)