【MOOC嵩天Python语言程序设计】3.2实例3:天天向上的力量

>>> 1.001**365
1.4402513134295205
>>> 0.999**365
0.6940698870404745
>>> 


>>> 1.01**365
37.78343433288728
>>> 0.99**365
0.025517964452291125


>>> pow(1.01,365)
37.78343433288728
>>> pow(1.02,365)
1377.4082919660768


dayup = pow(1.001,365)
daydown = pow(0.99,365)
print("向上:{:.2f},向上:{:.2f}".format(dayup,daydown))

向上:1.44,向上:0.03


dayfactor = 0.005
dayup = pow(1+dayfactor,365)
daydown = pow(1+dayfactor,365)
print("向上:{:.2f},向上:{:.2f}".format(dayup,daydown))

向上:6.17,向上:6.17


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))

工作日的力量:4.63


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
dayfactor = 0.01
while dayUP(dayfactor) < 37.8:
    dayfactor += 0.001
print("工作日努力的参数是:{:.3f}".format(dayfactor))

工作日努力的参数是:0.019

你可能感兴趣的:(Python)