# How to Calculate Compound Interest in Python?

17-Oct-2022

. Hi Dev,

This post will give you example of How to Calculate Compound Interest in Python?. We will look at example of Python Program for compound interest. you'll learn Python Program to Calculate Compound Interest. We will look at example of Calculate Compound Interest. So, let's follow few step to create example of Create A Python Program For Compound Interest using Function.

Now let’s see each python program for calculate or compute compound interest; as shown below:

let's see below simple example with output:

Example 1: Python program to compute compound interest

```#Python program to compute compound interest

p = float(input("Enter the principal amount : "))

t = float(input("Enter the number of years : "))

r = float(input("Enter the rate of interest : "))

#compute compound interest
ci =  p * (pow((1 + r / 100), t))

#print
print("Compound interest : {}".format(ci))
```

Output:

```Enter the principal amount :  1200
Enter the number of years :  2
Enter the rate of interest :  5.4
Compound interest : 1333.0992
```

Example 2: Python Program to Calculate Compound Interest using Function

```#Python program to compute compound interest using function

def compoundInterest(p, r, t):
ci = p * (pow((1 + r / 100), t))
return ci

p = float(input("Enter the principal amount : "))

t = float(input("Enter the number of years : "))

r = float(input("Enter the rate of interest : "))

#call compound interest
ci =  compoundInterest(p, r, t)

#print
print("Compound interest : {}".format(ci))
```

Output:

```Enter the principal amount :  1200
Enter the number of years :  2
Enter the rate of interest :  5.4
Compound interest : 1333.0992
```