Compound Interest

Compound interest (or compounding interest) is the interest calculated on the principal, including all cumulative interest on deposits or loans in the previous period. – Investopedia

Logic

To calculate compound interest we have to use a very simple formula shown below:

Compound interest formula

Where, P = Principle T = Time and R = Rate

To calculate compound interest we have to multiply principle amount with the power of (1 + Rate / 100) with time as an exponent. To calculate power we have used pow() function of the module Math.

Program

# Import math module for 'Pow' function
import math

# Take input from user (Principal, rate, time)
principal = float(input("Enter principal : "))
rate = float(input("\nEnter rate : "))
time = float(input("\nEnter time (year) : "));    

# Calculate compound interest 
result = principal * math.pow((1 + rate / 100), time)

'''
The pow(x, y) is equivalent to: x**y
'''

# Print the result
print("\nCompound interest :", result)

Output

Enter principal : 100
Enter rate : 25
Enter time (year) : 6
Compound interest : 381.4697265625