Program to find compound Interest using Python


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


p = principal amount

r = rate of interest

t = time period

amount = calculated amount

CI = Compound Interest

Program to find compound Interest

Below is the python code to calculate compound interest.


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: ")



Program to find compound Interest Output


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.

Leave a comment

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