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?
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, "%")
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?
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, "%")