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 161: 5.23

Answer

code

Work Step by Step

# 5.23 (Financial application: compare loans with various interest rates) Write a program # that lets the user enter the loan amount and loan period in number of years # and displays the monthly and total payments for each interest rate starting from # 5% to 8%, with an increment of 1/8. import math loanAmount = eval(input("Loan Amount: ")) years = eval(input("Number of Years: ")) print("Interest Rate Monthly Payment Total Payment") i = years counter = 1 while counter < 26: print(format(i, "-5.3f"), end='%') print(" ", end='') monthlyInterestRate = i / 1200 monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / math.pow(1 + monthlyInterestRate, years * 12)) print(format(monthlyPayment, "-5.2f"), end='') print(format((monthlyPayment * 12) * years, "-24.2f")) counter += 1 i += .125
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.