Zed-King Institute

    Python Program to Calculate Simple Interest

    easyInput and operatorsPython

    A formula program seen in almost every beginner exam. It reads three values and applies the simple interest formula.

    The question

    Read the principal, the rate of interest (% per year) and the time in years — three integers, one per line. Print the simple interest SI = P × R × T / 100.

    The code

    program.py

    p = int(input())
    r = int(input())
    t = int(input())
    si = p * r * t / 100
    print("Simple Interest =", si)

    Input

    37000
    4
    3

    Output

    Simple Interest = 4440.0

    How it works

    1. 1Read principal p, rate r (per cent per year) and time t in years.
    2. 2Simple interest is p × r × t / 100.
    3. 3Print the result; since / is used, it prints with a decimal point.

    Common mistakes

    • Forgetting to divide by 100 — the rate is a percentage.
    • Reading all three values on one line when the question gives them on separate lines.

    With decimal values and the total amount

    A rate such as 7.5% is not a whole number, so read the values with float(). The total amount to pay back is the principal plus the interest.

    program.py

    p = float(input())
    r = float(input())
    t = float(input())
    si = p * r * t / 100
    print("Simple Interest =", si)
    print("Total Amount =", p + si)

    Input

    5000
    7.5
    2

    Output

    Simple Interest = 750.0
    Total Amount = 5750.0

    Simple interest using a function

    When the question says "write a function", put the formula inside def and return the answer instead of printing it.

    program.py

    def simple_interest(p, r, t):
        return p * r * t / 100
    
    print("Simple Interest =", simple_interest(10000, 8, 3))

    Input

    (no input)

    Output

    Simple Interest = 2400.0

    Questions students ask

    What is the formula for simple interest in Python?
    si = p * r * t / 100, where p is the principal, r is the rate of interest in per cent per year and t is the time in years. The * and / operators are worked out from left to right.
    Why does the answer print as 2400.0 and not 2400?
    The / operator in Python 3 always returns a float, even when the division is exact. Write int(si) or use // 100 only if the question asks for a whole number.
    How do I find the total amount?
    Add the interest to the principal: amount = p + si. For ₹5,000 at 7.5% for 2 years the interest is ₹750 and the amount is ₹5,750.

    Now solve a similar question yourself

    A new Python question every time, checked instantly.

    Practice questions

    Preparing for NIELIT O Level?

    This program is the kind asked in the M3 (Python) theory paper and the PR-3 practical exam.

    More in Input and operators