DEV Community

Lakshmi Pritha Nadesan
Lakshmi Pritha Nadesan

Posted on

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:", 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))
Enter fullscreen mode Exit fullscreen mode

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: 0.002916666666666667
EMI: 4944.29


Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay