小编mil*_*loJ的帖子

具有复利的Python递归

我正在尝试在Python中建立一个递归函数来查找复利。到目前为止,这是我的代码。

def compound_interest(principal, rate, years):
    return principal*(1 + rate)**years

def compound_interest_recursive(principal, rate, years)
    if years == 0:
        return principle
    else:
        return 



principal_str = input("Enter the principal ")
principal = int(principal_str)

rate_float = input("Enter the interest rate ")
rate = float(rate_float)

years_str = input("Enter the number of years ")
years = int(years_str)

print("Principal after", years,"year(s) is",compound_interest\
      (principal, rate, years))
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我我所缺少的吗?谢谢。我试图让它输入数字,然后打印出来。

python recursion

0
推荐指数
1
解决办法
8093
查看次数

标签 统计

python ×1

recursion ×1