Python Program to Calculate Compound Interest

Python Program to compute or calculate compound interest; Through this tutorial, i am going to show you how to calculate or compute compound interest in python.

Please look at the compound interest rate formula.

A = p * (pow((1 + r / 100), t))

A=final amount
p=initial principal balance
r=interest rate
t=number of time periods elapsed

Python Program to Calculate Compound Interest

  • Python program to compute compound interest
  • Python Program to Calculate Compound Interest using Function

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 :  1000 
Enter the number of years :  2 
Enter the rate of interest :  5 
Compound interest : 1102.5 

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 :  1000 
Enter the number of years :  2 
Enter the rate of interest :  5 
Compound interest : 1102.5  

Recommended Python Tutorials

Recommended:-Python Map() Method

Leave a Comment