ByteBoard Notes Notes

To calculate EMI for amount, period and interest

Informatics Practices XI · Experiment 06 of 36 · Python

★ CBSE suggested11-IPPython programs
Expt. No.06
Page No.12

EMI calculator

Aim

To write a Python program that calculates the monthly EMI for a loan amount, the period in years and the annual interest rate.

Concepts used

Algorithm

  1. Input the loan amount P, the annual rate and the period in years.
  2. Monthly rate r = annual rate ÷ 12 ÷ 100; number of months n = years × 12.
  3. EMI = P × r × (1 + r) n ÷ ((1 + r) n − 1).
  4. Display the EMI, total payment and total interest.

Program

# EMI calculator p = float(input("Loan amount        : "))rate = float(input("Interest (% a year): "))years = float(input("Period (years)     : ")) r = rate / 12 / 100n = years * 12emi = p * r * (1 + r) ** n / ((1 + r) ** n - 1)print("Monthly EMI   :", round(emi, 2))print("Total payment :", round(emi * n, 2))print("Total interest:", round(emi * n - p, 2))

A marked line continues the line above it. In your file, write it on the same line.

Output

$ python emi_calculator.py
Loan amount : 500000 Interest (% a year): 9 Period (years) : 5 Monthly EMI : 10379.18 Total payment : 622750.66 Total interest: 122750.66

✓ Printed by running this program, not typed by hand.

Result

A loan of 5,00,000 at 9% for 5 years gives an EMI of 10379.18 a month; over 60 months the total payment is 622750.66, of which 122750.66 is interest.

Viva voce: what the examiner may ask

01Why is the rate divided by 12 and by 100?

EMI is paid monthly, so the yearly rate is split into 12, and dividing by 100 turns a percentage into a fraction.

02Why are brackets used around ((1 + r) ** n - 1)?

So the whole expression is the divisor; without them only part of it would be divided.

03What is EMI?

Equated Monthly Instalment: the fixed amount paid every month to repay a loan with interest.

Variations for the lab test

  1. Display the EMI for 3, 5 and 7 years in a loop.
  2. Take the period in months instead of years.
  3. Find the EMI when the rate is 0% (hint: EMI = P ÷ n).
! Common mistake Using the yearly rate as r without dividing by 12 gives an EMI that is far too high.
Back to the 11-IP index