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.


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment