In: Computer Science
The monthly payment for a given loan pays the principal and the interest. The monthly interest is computed by multiplying the monthly interest rate and the balance (the remaining principal). The principal paid for the month is therefore the monthly payment minus the monthly interest. Write a pseudocode and a Python program that let the user enter the loan amount, number of years, and interest rate, and then displays the amortization schedule for the loan (payment#, interest, principal, balance, monthly payment). Hint: use pow function (example, pow (2, 3) is 8. Same as 2 **3. ); monthly payment is the same for each month, and is computed before the loop.
Amortization Schedule: An amortization is a complete table of periodic loan payment,showing
the amount of principle and the amount of interest that comprise each payment until the loan is paid off at the end of its term.
Source Code:
loan_amount = int(input("Enter the loan amount:"))
number_of_years = int(input("Enter the number of years"))
interest_rate = float(input("Enter the rate of interest in decimals:"))
r = (interest_rate / 12)/100 # Calculate monthly interest rate
n = number_of_years * 12 # calculate the total number of payments
monthly_payment = loan_amount*r*(pow((1+r),n)) / (pow((1+r),n)-1)
print("Payment","\t","Interest","\t"," Principle Bal.","\t","Monthly payment")
for i in range(1,n+1):
interest =(loan_amount*interest_rate/12/100)
p_dep = monthly_payment - interest
principle_rem = loan_amount - p_dep
loan_amount = principle_rem
print(i,"\t\t\t","%5.2f"%(interest),"\t\t","%5.2f"%(principle_rem),"\t\t\t","%5.2f"%(monthly_payment))