Python Program to calculate Compound Interest


Way 1 – Calculate Compound Interest

In [1]:
principal = float(input("Enter the principal amount : "))
time = float(input("Enter the time period : "))
rate = float(input("Enter the rate of interest : "))

amount = principal*(1 + (rate/100))**time

compount_interest = amount-principal

print("Compount Interest =", compount_interest)
Enter the principal amount : 4000
Enter the time period : 2
Enter the rate of interest : 4
Compount Interest = 326.40000000000055

In this program, we will ask the user to input principal, rate and time. After that, use the compound interest formula.

Way 2 – Compound Interest using power function

In [1]:
principal = float(input("Enter the principal amount : "))
time = float(input("Enter the time period : "))
rate = float(input("Enter the rate of interest : "))

amount = principal*(pow(1 + (rate/100),time))

compount_interest = amount-principal

print("Compount Interest =", compount_interest)
Enter the principal amount : 4000
Enter the time period : 2
Enter the rate of interest : 4
Compount Interest = 326.40000000000055

This program is the same as the above program, the only difference is that here we were using the pow() function to find the power.