Header Ads

How do you calculate compound interest in Python?

What is Compound Interest ?

Compound interest (or compounding interest) is the interest on a loan or deposit calculated based on both the initial principal and the accumulated interest from previous periods.

Compound Interest formula:

Formula to calculate compound interest annually is given by: 

A = P(1 + R/100) t 

Compound Interest = A – P 

Where, 
A is amount 
P is principle amount 
R is the rate 
T is the time in years


Code :


def CompoundInterest(principle, rate, time):
    Amount = principle * pow(1+rate/100, time)
    CI = Amount - principle
    print("Compound Interest = ",CI)

p = float(input("Enter Principle Amount : "))
r = float(input("Enter Rate of Interest per annum : "))
t = float(input("Time in years : "))
CompoundInterest(p, r, t)


Output :

Enter Principle Amount : 11000
Enter Rate of Interest per annum : 11.25
Time in years : 6
Compound Interest =  9854.164888652806

Explanation :

We have to define a function which takes 3 arguments principle, rate and time. Now using the formula calculate compound interest and print the output

Post a Comment

0 Comments