如何使用Python计算复利问题中的利率率。

huangapple go评论95阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年3月7日 14:44:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658724.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定