Q3:工作日每天努力进步1%,周末休息退步1%,一年后,输出结果:4.63
# coding=utf-8 dayup = 1.0 dayfactor = 0.01 for i in range(365): if i % 7 in [6, 0]: dayup = dayup*(1-dayfactor) else: dayup = dayup*(1+dayfactor) print("工作日的力量:{:.2f}".format(dayup))
Q4:只在工作日努力,休息日退步1%,需要每天努力多少,才能追赶上每天进步1%连续努力365天每的同学
# coding=utf-8 def dayUP(df): dayup = 1 for i in range(365): if i % 7 in [6, 0]: dayup = dayup * (1 - 0.01) else: dayup = dayup * (1 + df) return dayup df = 0.01 i = 0 while dayUP(df) < 37.78: i += 1 df += 0.001 print("工作日的努力参数是:{:.4f}".format(df)) print("循环的次数是:{}".format(i))
输出结果:
D:pytestvenvScriptspython.exe D:/pytest/SongTian/3.2ddupQ4.py 工作日的努力参数是:0.0190 循环的次数是:9
Q5:3天打鱼,2天晒网
def dayup(df): dayup = 1.0 for i in range(365): if i % 5 in [4, 0]: dayup = dayup * (1-0.01) else: dayup = dayup * (1+df) return dayup df = 0.01 while (dayup(df)<37.78): df += 0.001 print("{}".format(df))