我正在尝试在 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))
有人可以告诉我我错过了什么吗?谢谢。我试图让它输入数字然后打印出来。