Compound Interest Calculator

Calculate compound interest.

IntermediatePhase 6 - Category 5: Real-World Logic ProblemsExample 5 of 15
compound-interest-calculator.py
1# Take inputs
2principal = float(input("Enter principal: "))
3rate = float(input("Enter rate (%): "))
4time = float(input("Enter time (years): "))
5compounds = int(input("Enter compounds per year: "))
6
7# Calculate
8amount = principal * (1 + rate / (100 * compounds)) ** (compounds * time)
9interest = amount - principal
10
11print(f"Compound Interest: {interest:.2f}")
12print(f"Total Amount: {amount:.2f}")

Output

Enter principal: 10000
Enter rate (%): 5
Enter time (years): 2
Enter compounds per year: 12
Compound Interest: 1048.18
Total Amount: 11048.18

What's going on

Calculate compound interest using formula.

Key Concepts:

A = P * (1 + r/n)^(n*t)
CI = A - P
Compound interest formula