# 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:-

Loading...

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

A = P(1 + R/100)

Where,

A is the amount of money accumulated after n years, including interest.

P is the principal amount

R is the rate and

T is the time span

^{T}Where,

A is the amount of money accumulated after n years, including interest.

P is the principal amount

R is the rate and

T is the time span

## Python Program to Calculate Compound Interest

def compound_interest(principle, rate, time): result = principle * (pow((1 + rate / 100), time)) return result p = float(input("Enter the principal amount: ")) r = float(input("Enter the interest rate: ")) t = float(input("Enter the time in years: ")) amount = compound_interest(p, r, t) interest = amount - p print("Compound amount is %.2f" % amount) print("Compound interest is %.2f" % 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 amount is 176234.17

Compound interest is 76234.17

Enter the interest rate: 12

Enter the time in years: 5

Compound amount is 176234.17

Compound interest is 76234.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.

Loading...

This formula used is for finding amount. Please correct it. We can substract the amount from principal to get the CI.

A-P = CI

Thank you for the feedback. The blog has been updated with the new code.

Simple and compound dono ka chahiye program lakin ek hi esme aaya hai