Python Practice › Basic Programs › Program 27
Compound interest
Write a Python program to calculate compound interest. Amount = P × (1 + R/100)ᵀ and interest = amount − P.
Input
P = 10000, R = 8, T = 5 (compounded yearly)
Output
Amount: 14693.28 Compound interest: 4693.28
Approach
- Compute the final amount with the formula.
- Subtract the principal to get the interest.
Solution
principal = 10000rate = 8years = 5 amount = principal * (1 + rate / 100) ** yearsinterest = amount - principalprint("Amount:", round(amount, 2))print("Compound interest:", round(interest, 2))Output
Amount: 14693.28 Compound interest: 4693.28
Line by line
Line 5
(1 + rate / 100) is the growth factor per year; ** years applies it for every year.
Lines 7-8
round(..., 2) shows rupees and paise.
Learn the concept
New to this topic? Read the lesson, then come back.