Python Program to Calculate Compound Interest

Python Program to Calculate Compound Interest
Reading Time: 3 minutes

Introduction:

Compound interest is a concept in finance that allows an initial amount of money, called the principal, to grow over time by adding the interest earned to the principal. This interest is then reinvested, resulting in exponential growth. In this Python program, we will calculate compound interest based on the principal amount, interest rate, and the number of years.

Algorithm:

  1. Take the principal amount, interest rate, and number of years as input from the user.
  2. Calculate the compound interest using the formula: compound_interest = principal_amount * (1 + interest_rate/100) ** number_of_years – principal_amount
  3. Display the compound interest to the user.

Now let's write the Python program to calculate compound interest:

    
     # Input principal amount, interest rate, and number of years
principal_amount = float(input("Enter the principal amount: "))
interest_rate = float(input("Enter the interest rate (in percentage): "))
number_of_years = int(input("Enter the number of years: "))
# Calculate compound interest
compound_interest = principal_amount * (1 + interest_rate/100) ** number_of_years - principal_amount
# Display the compound interest
print("Compound Interest: ", compound_interest)

    
   

Input :

    
     Enter the Principle amount : 5000
Enter the interest Rate (percentage) : 5.5
Enter the number of Years : 3
    
   

Output :

    
     Compound Interest : 854.375
    
   

Explanation:

In the above program, we take the principal amount, interest rate, and number of years as input from the user. We then calculate the compound interest using the given formula and display the result to the user.