Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 5 - Loops - Programming Exercises - Page 162: 5.24

Answer

code

Work Step by Step

# 5.24 (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 the # monthly 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. loanAmount = eval(input("Loan amount: ")) numOfYears = eval(input("Number of years: ")) annualIR = eval(input("Annual Interest Rate: ")) print() monthlyIR = annualIR / 1200 monthlyPayment = loanAmount * monthlyIR / (1 - (pow(1 / (1 + monthlyIR), numOfYears * 12))) balance = loanAmount print("Monthly Payment:", int(monthlyPayment * 100) / 100.0) print("Total Payment:", int(monthlyPayment * 12 * numOfYears * 100) / 100.0) print() print(format("Payment#", "<15s"), format("Interest", "<15s"), format("Principal", "<15s"), format("Balance", "<15s")) for i in range(1, numOfYears * 12 + 1): interest = int(monthlyIR * 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"))
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.