Home > Article > Backend Development > Write a program to EMI calculator
EMI calculator:
An EMI Calculator helps you estimate your monthly installments easily. Once you enter the necessary details such as the loan amount, loan term, and interest rate, the bank's EMI calculator will instantly display your estimated Equated Monthly Installment (EMI).
To calculate your EMI, you can use the following formula:
EMI = [P x R x ( 1 R )^N] / [( 1 R )^N -1]
Where :
P = Principal Amount
R = Monthly Interest Rate (Annual Interest Rate / 12 months)
N = Loan Tenure in months
Example:
# Input the loan amount loan = int(input("Enter the loan amount: ")) # Input the loan tenure in years and convert to months tenure_year = int(input("Enter the loan tenure in years: ")) tenure_month = tenure_year * 12 # Convert years to months print("Loan tenure in months:", tenure_month) # Input the interest rate per year and convert to monthly interest rate interest_year = float(input("Enter the interest per year: ")) interest_month = interest_year / 12 / 100 # Convert annual interest rate to monthly decimal rate print("Interest per month in percentage:", interest_month) # Calculate EMI using the formula emi = loan * (interest_month * (1 + interest_month) ** tenure_month) / ((1 + interest_month) ** tenure_month - 1) # Display the calculated EMI, rounded to 2 decimal places print("EMI:", round(emi, 2))
Output:
Enter the loan amount:500000 Enter the loan tenure in years :10 Loan tenure in months: 120 Enter the interest per year:3.5 Interest per month in percentage: 0.002916666666666667 EMI: 4944.29
The above is the detailed content of Write a program to EMI calculator. For more information, please follow other related articles on the PHP Chinese website!