# Program to find compound Interest using Python

## Introduction

In the previous section, we have understood the code to calculate the simple interest. Now we will understand to write the code for compound interest. The formula for compound interest is,

amount = p*(1+r/100)t

CI = amount – p

Where,

p = principal amount

r = rate of interest

t = time period

amount = calculated amount

CI = Compound Interest Below is the python code to calculate compound interest.

## Program

```def interest(p,r,t):
amount = float(p)
rate = float(r)
time = float(t)
amt = float(amount*(pow((1+rate/100),time)))
c_interest = float(amt-amount)
print("The compound interest for principle amount {0}, rate of interest {1} and time period {2} is {3}".format(amount,rate,time,c_interest))
#User input
p = input("Please enter the principle amount: ")
r = input("Please enter the rate of interest: ")
t = input("Please enter the time period: ")

interest(p,r,t)```

## Output ## Explanation

In the above program to calculate the compound interest, we have taken the input values for principal amount, rate of interest and time period from the user and the input is scanned through input() function. The function interest() is called and input values are passed as arguments to calculates the interest amount and display the output result which is stored in variable c_interest.

This site uses Akismet to reduce spam. Learn how your comment data is processed.