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