python计算年收益
# -------------------------------------------------------------------------------
# 计算年收益
# per_year_money 每年投资金额
# ratio 年化率
# year 总年数
# -------------------------------------------------------------------------------
def compute(per_year_money, ratio, year):
if year == 1:
return per_year_money * (1 + ratio)
else:
return (compute(per_year_money, ratio, year - 1) + per_year_money) * (1 + ratio)
# 每年投资金额
per_year_money = 600
# 年化率
ratio = 15 / 100
# 总年数
year = 10
for i in range(1, year + 1):
print("第{}年".format(i), "{} 元".format("%.2f" % (compute(per_year_money, ratio, i))))
以上是 python计算年收益 的全部内容, 来源链接: utcz.com/z/530272.html