← Back

Home › Python programs (Hindi)

Simple Interest Program Python में — code और dry run

Read this in English

Problem statement

Principal, rate और time से simple interest निकालना: SI = P × R × T / 100। Interest और कुल लौटाने योग्य amount दोनों print करना।

Approach 1: simple loop

Apply the formula directly. The division by 100 exists because R is a percentage, not a fraction — 7.5 means 7.5 per hundred.

p = 5000        # principal (rupees)
r = 7.5         # rate per year (percent)
t = 2           # time (years)

si = p * r * t / 100
print("Interest:", si)
print("Total:", p + si)
# Output:
# Interest: 750.0
# Total: 5750.0

Multiplication and division have equal precedence and run left to right, so p * r * t / 100 needs no brackets.

Approach 2: reusable function

Wrap it in a function so the inputs and the formula are separated — then the same three lines serve savings accounts, loans, and exam questions alike.

def simple_interest(p, r, t):
    return p * r * t / 100

def total_amount(p, r, t):
    return p + simple_interest(p, r, t)

print(simple_interest(5000, 7.5, 2))    # 750.0
print(total_amount(5000, 7.5, 2))       # 5750.0
print(simple_interest(12000, 10, 1))    # 1200.0

One function, one job — and total_amount builds on it instead of repeating the formula.

Approach 3: Pythonic alternative

Real programs read inputs and format outputs. Convert at the boundary with float(), and present money with f-string formatting to two decimals.

p = float(input("Principal: "))
r = float(input("Rate % per year: "))
t = float(input("Years: "))

si = p * r * t / 100
print(f"Interest = {si:.2f}")
print(f"Total payable = {p + si:.2f}")
# For inputs 5000, 7.5, 2:
# Interest = 750.00
# Total payable = 5750.00

{si:.2f} prints exactly two decimals — 750.00 instead of 750.0 — which is what money deserves.

Dry run

P=5000, R=7.5, T=2 को formula में चलाएँ: 5000 × 7.5 = 37500। 37500 × 2 = 75000। 75000 / 100 = 750.0। Total = 5000 + 750 = 5750.0। एक सुखद check: simple interest linear होता है — एक साल में 375, तो दो साल में ठीक 750। अगर trace में interest principal के बराबर या उससे बड़ा आए, तो /100 छूट गया है।

Common errors

Practice on PyDebug

Concept समझने के बाद इन free problems को browser में solve करें: