How to calculate the rate of interest in compound interest problem using python

Question:

I know how to calculate compound interest in python using this function:

def compound_interest(principal, rate, time):
 
    # Calculates compound interest
    Amount = principal * (pow((1 + rate / 100), time))
    CI = Amount - principal
    print("Compound interest is", CI)

I want to input the principal amount, final amount, time to the function and it should output the rate. how do I do that?

Asked By: KawaiKx

||

Answers:

you need to rearange your formula.

rate = (100 * (final_amount/principal)**(1/time)) - 100

in function:

def rate_interest(principal, final_amount, time):
    rate = (100 * (final_amount/principal)**(1/time)) - 100
    print("Compound interest rate is", rate, "%")
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.