英文:
How to calculate the rate of interest in compound interest problem using python
问题
我知道如何在Python中使用这个函数来计算复利:
def compound_interest(principal, rate, time):
# 计算复利
Amount = principal * (pow((1 + rate / 100), time))
CI = Amount - principal
print("复利是", CI)
我想要将本金、最终金额和时间输入到函数中,然后输出利率。我该如何做到这一点?
英文:
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?
答案1
得分: 3
你需要重新调整你的公式。
在函数中:
def rate_interest(principal, final_amount, time):
rate = (100 * (final_amount/principal)**(1/time)) - 100
print("复利利率是", rate, "%")
英文:
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, "%")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论