Python Program to Calculate Compound Interest

In this example, we will write a program that calculates the compound interest in Python. To better understand this example, make sure you have knowledge of the following tutorials:-

Let us have a look at the formula for calculating the simple interest.

Compound Interest = P(1 + R/100)r
Where,
P is the principle amount
R is the rate and
T is the time span

Python Program to Calculate Compound Interest

The output of the above program is:-

Enter the principal amount: 100000
Enter the interest rate: 12
Enter the time in years: 5
Compound interest is 176234.17
In this program, the user input is taken using input() function which takes input as a string. But as we are doing the calculation part, we need the input to be a float. So, we did the type-conversion using float() function.
The input from the user is taken as p for the principal amount, t for the time in years and r for the interest rate. The function is defined with def keyword that takes three arguments,  principal, rate and time. The formula is applied and result is returned to the calling function and the output is displayed using print() function.
SHARE Python Program to Calculate Compound Interest

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Share