Python Practice › Basic Programs › Program 27

Compound interest

EasyBasic Programs · 27 of 40

Write a Python program to calculate compound interest. Amount = P × (1 + R/100)ᵀ and interest = amount − P.

Advertisement
Input
P = 10000, R = 8, T = 5 (compounded yearly)
Output
Amount: 14693.28
Compound interest: 4693.28

Approach

  1. Compute the final amount with the formula.
  2. Subtract the principal to get the interest.

Solution

Python
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.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More basic programs

← All 40 Basic Programs