(Financial application: loan amortization schedule) 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 thenmonthly interest. Write a program that lets the user enter the loan amount, number of years, and interest rate, and then displays the amortization schedule for the loan.

Note

The balance after the last payment may not be zero. If so, the last payment should be the normal monthly payment plus the final balance.

Hint

Write a loop to display the table. Since the monthly payment is the same for each month, it should be computed before the loop. The balance is initially the loan amount. For each iteration in the loop, compute the interest and principal and update the balance. The loop may look like this:

for i in range(1, numberOfYears * 12 + 1):

interest = monthlyInterestRate * balance

principal = monthlyPayment - interest

balance = balance - principal

print(i, "\t\t", interest, "\t\t", principal, "\t\t", balance)

This is the code that I have

- Code: Select all
`balance = int(input("Enter the loan amount: "))`

years = int(input("Enter the number of years: "))

months = years * 12

interest = eval(input("Enter the interest rate: "))

monthlyinterest = interest /(100*12)

monthlypayment = balance * (monthlyinterest* (1 + monthlyinterest) ** months)/ ((1 + monthlyinterest)** months -1 )

totalpayment = monthlypayment * months

print()

print('Monthly payment: ', format(monthlypayment,'.2f'))

print('Total amount of payments: ', format(totalpayment,'.2f'))

print()

print ('Payment#\t', 'Interest\t', 'Principal\t', 'Balance')

print ('---------------------------------------------------------')

for p in range(1, months+1):

interest = monthlyinterest * balance

principal = monthlypayment - interest

balance -= principal

print (p,'\t\t',format(interest,'.2f'), '\t\t', format(principal,'.2f'), '\t', format(balance,'.2f'))

The problem that I am having is that my final balance is 0.00 when it's suppose to be 0.01 it looks like there's an issue with the way the program is rounding my results but I am not sure how to fix it. I was hoping you guys could help me head in the right direction.