Simple Interest Program in Python
Problem statement
Compute simple interest from principal, rate and time: SI = P × R × T / 100. Print the interest and the total amount to be repaid.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.0Multiplication 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.0One 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
Trace P=5000, R=7.5, T=2 through the formula: 5000 × 7.5 = 37500. 37500 × 2 = 75000. 75000 / 100 = 750.0. Total = 5000 + 750 = 5750.0. A useful check: simple interest is linear — one year earns 375, so two years earn exactly 750. If your trace shows interest doubling the principal, the /100 has gone missing.
Common errors
- Forgetting the
/ 100— the answer arrives a hundred times too big, the single most common slip. - Reading
input()withoutfloat()—"5000" * 7.5raises a TypeError. - Confusing simple with compound interest — compound uses
p * (1 + r/100) ** tand grows on the growing balance. - Rounding the interest before adding to the principal — round only for display, keep full precision for arithmetic.
- Naming the rate as a fraction (0.075) but still dividing by 100 — pick one convention and stay with it.
Practice on PyDebug
Turn the idea into a debugging habit with these free browser exercises: