# Find the compound interest from the given Principal, No. of Years, and Rate of Interest

Hello everyone, welcome to nkcoderz.com. In this article we will going to discuss about Find the compound interest from the given Principal, No. of Years, and Rate of Interest.

## Find the compound interest from the given Principal, No. of Years, and Rate of Interest

``````def compound_interest(principal, rate, years):
return principal * (1 + rate / 100) ** years

# test the function
print(compound_interest(1000, 5, 3))
``````

## Output

`1157.625`

## Explanation

The function `compound_interest(principal, rate, years)` takes in three parameters:

• `principal`: the initial amount of money you’re depositing (or the “present value”)
• `rate`: the annual interest rate (should be expressed as a percentage, e.g. 5 for 5%)
• `years`: the number of years for which the interest will be compounded

The function calculates the compound interest using the formula : A = P(1 + r/100)^n Where A is the final amount, P is the principal, r is the rate of interest and n is the number of times the interest is compounded per unit t (in this case annually)

You can also use the `math.pow` method to achieve the same result

``````import math
def compound_interest(principal, rate, years):
return principal * math.pow((1 + rate / 100), years)``````

Python program to find the power ‘n’ of the given number ‘a’

## Conclusion

If you liked this post, then please share this with your friends and make sure to bookmark this website for more awesome content.