抖音上有个很火的存钱计划,说是第一天存1块钱,第二天存2块钱,第三天存3块钱.....依此类推存365天,总共可以存到多少钱,我们现在用python告诉你怎么做:
#定个初始存入金额 money = 1 #定义个空数组,用来接收每天存入的钱 total = [] #通过for循环来实现 for day in range(1,366): if day == 1: print(f"第{day}天存{money}元钱,到第{day}天存到{sum(total)+money}元钱!") else: money += 1 print(f"第{day}天存{money}元钱,到第{day}天存到{sum(total)+money}元钱!") total.append(money) #直接打印出总和 print(f"总共存到{sum(total)}元钱。")