# Compound interest program in Python

Written by

Himani Kohli

## Python program to find Compound interest

In this example, we will learn how to find a compound interest using python.

In this program, we should know the formula and basic concepts to solve the question.

The formula for calculating compound interest is:

A = P * (1 + r/n)^(n*t)

where:

A is the future value of the investment/loan, including interest P is the principal investment amount (the initial deposit or loan amount) r is the annual interest rate (expressed as a decimal) n is the number of times that interest is compounded per year t is the number of years the money is invested or borrowed for

Algorithm:

1. Prompt the user to input the principal amount, which is the initial amount of money invested or borrowed.
2. Prompt the user to input the interest rate, which is the percentage of the principal amount that will be added as interest.
3. Prompt the user to input the number of years for which the interest will be compounded.
4. Use a for loop to iterate through the number of years, and use the formula `A = P * (1 + r/n)^(n*t)` to calculate the compound interest for each year. This formula calculates the future value of the investment or loan, including interest, based on the principal amount, interest rate, and number of years.
5. Print the result of the calculation to the screen. You can use a function like printf or cout to do this.
6. End the program.

Code:

``````n = int(input("Enter the principle amount:"))

rate = int(input("Enter the rate:"))

years = int(input("Enter the number of years:"))

for i in range(years):
n = n + ((n * rate) / 100)

print(n)

``````

Output:

``````Enter the principle amount:100

Enter the rate:2

Enter the number of years:2

104.04
``````