Python学习(11)---4月8日打卡

1、1.0版本

Python学习(11)---4月8日打卡

Python学习(11)---4月8日打卡

Python学习(11)---4月8日打卡

Python学习(11)---4月8日打卡

"""
功能:52周存钱挑战
版本:1.0
"""
def main():
    """主函数"""
    money_per_week=10 #每周的存入金额
    i=1               #记录周数
    increase_money=10 #递增的金额
    total_week=52     #总共的周数
    saving=0          #账户累计
    while i<=total_week:
        #存钱操作
        saving=saving+money_per_week

        #输出信息
        print('第{}周,存入{}元,账户累计{}元'.format(i,money_per_week,saving))
        #更新下一周存钱金额
        money_per_week+=increase_money
        i+=1

if __name__ == '__main__':
    main()

2、2.0版本

Python学习(11)---4月8日打卡

Python学习(11)---4月8日打卡

Python学习(11)---4月8日打卡

Python学习(11)---4月8日打卡

"""
功能:52周存钱挑战
版本:1.0
"""
import math
def main():
    """主函数"""
    money_per_week=10 #每周的存入金额
    i=1               #记录周数
    increase_money=10 #递增的金额
    total_week=52     #总共的周数
    saving=0          #账户累计
    money_list=[]    #存钱数的列表

    while i<=total_week:
        #存钱操作
        # saving=saving+money_per_week
        money_list.append(money_per_week)
        saving=math.fsum(money_list)
        #输出信息
        print('第{}周,存入{}元,账户累计{}元'.format(i,money_per_week,saving))
        #更新下一周存钱金额
        money_per_week+=increase_money
        i+=1

if __name__ == '__main__':
    main()