python计算年收益[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))))

hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » python计算年收益