220k views
3 votes
Kim wants to buy a car. Help Kim compute the monthly payment on a loan, given the loan amount, the annual percentage rate of interest, and the number of monthly payments.The program should allow Kim to input the loan amount, interest rate, and how many payments she wants to make.It should then compute and display the monthly payment.You will need the following variables:Payment LoanAmt InterestRateMonthlyRate NumberMonthsYou will need the following formulas:MonthlyRate = InterestRate/1200Note: when the user enters InterestRate as a percentage, it must be divided by 100 to make it a decimal (i.e., 18% = 18/100 = 0.18).The InterestRate offered by car dealers is an annual rate so this must be divided by 12 to get the MonthlyRate.The formula given above combines the two steps (i.e., annual rate of 18% = 18/100 = 0.18 and the monthly rate is 0.18/12 = 0.015 or 18/(100*12) = 18/1200.Payment = LoanAmt * MonthlyRate * (1 +MonthlyRate)^NumberMonths (divided by) ((1 +MonthlyRate)^NumberMonths -1)Note: The formula must be entered carefully, exactly as shown.

User Kobame
by
5.6k points

1 Answer

0 votes

Answer:

The complete Python program to calculate the monthly payment on a loan with step by step explanation is given below.

Python Code with Explanation:

# get the loan amount from the user

LoanAmt=eval(input("Please enter the loan amount: "))

# get the annual interest rate from the user in percentage form

InterestRate=eval(input("Please enter the annual interest rate in percentage: "))

# get the number of months from the user

NumberMonths=eval(input("Please enter the number of months: "))

# convert the annual interest rate into monthly interest rate and also into decimal form according to the equation given in the question

MonthlyRate = InterestRate/1200

# implement the given equation to find out the required monthly payment, the operator (**) is used to raise to the power

Payment = (LoanAmt*MonthlyRate (1+MonthlyRate)**NumberMonths)/((1+MonthlyRate)**NumberMonths -1)

# finally, print the monthly payment

print("The monthly payment is: ", Payment)

Output:

Please enter the loan amount: 1500

Please enter the annual interest rate in percentage: 15

Please enter the number of months: 12

The monthly payment is: 135.38746851773584

Bonus:

You can use this command to limit the digits after the decimal point

For example following code will limit to 2 digits after the decimal point.

print(format(Payment, '.2f'))

Kim wants to buy a car. Help Kim compute the monthly payment on a loan, given the-example-1
User Pkis
by
5.7k points