Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Question (Financial application: loan amortization schedule) The monthly payment for a given loan pays the principal and the interest. The monthly interest is computed

Python Question

(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)

I tried doing this problem but didnt do it correctly right. The code below is what I did but I didnt get the full credit, the TA said that "Add Validations in the code instead of asking/expecting a valid input from user. Like values should be positive integer and all." How do i add that?

This is my code:

loanAmount = float(input("Enter loan amount, for example 120000.95: "))

numOfYears = eval(input("Enter number of years as an integer, for example 5: "))

annualInterestRate = eval(input("Enter yearly interest rate, for example 8.25: "))

monthlyInterestRate = annualInterestRate/1200

monthlyPayment = loanAmount*monthlyInterestRate / \ (1 - (pow(1 / (1 + monthlyInterestRate), numOfYears * 12)))

balance = loanAmount print("Monthly Payment:", int(monthlyPayment * 100) / 100.0) print("Total Payment:", int(monthlyPayment * 12 * numOfYears * 100) / 100.0)

print(format("Payment#", "<15s"), format("Interest", "<15s"), format("Principal", "<15s"), format("Balance", "<15s")) for i in range(1, numOfYears * 12 + 1): interest = int(monthlyInterestRate * balance * 100) / 100.0 principal = int((monthlyPayment - interest) * 100) / 100.0 balance = int((balance - principal) * 100) / 100.0 print(format(i, "<15d"), format(interest, "<15.2f"), format(principal, "<15.2f"), format(balance, "<15.2f"))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

Explain the nature of paid work

Answered: 1 week ago