dayfactor=0.01
dayup=pow(1+dayfactor,365)
daydown=pow(1-dayfactor,365)
print("向上:{:.2f},向下:{:.2f}".format(dayup,daydown))
>>>向上:37.78,向下:0.03
dayup=pow(1.001,365)
daydown=pow(0.999,365)
print("向上:{:.2f},向下:{:.2f}".format(dayup,daydown))
>>>向上:1.44,向下:0.69
dayfactor=0.005
dayup=pow(1+dayfactor,365)
daydown=pow(1-dayfactor,365)
print("向上:{:.2f},向下:{:.2f}".format(dayup,daydown))
>>>向上:6.17,向下:0.16
dayfactor=0.01
dayup=1
for i in range(365):
if i%7 in [6,0]:
dayup*=(1-dayfactor)
else:
dayup*=(1+dayfactor)
print("向上:{:.2f}".format(dayup))
封装为函数:
def daydayup(dayfactor,dayup=1):
for i in range(365):
if i%7 in [6,0]:
dayup*=(1-dayfactor)
else:
dayup*=(1+dayfactor)
print("向上:{:.2f}".format(dayup))
daydayup(0.04)
def daydayup(df):
dayup=1
for i in range(365):
if i%7 in [6,0]:
dayup*=(1-0.01)
else:
dayup*=(1+df)
return dayup
# print("向上:{:.2f}".format(dayup))
dayfactor=0.01
while daydayup(dayfactor)< pow(1.01,365):
dayfactor+=0.001
print("平时努力的因素是:{:.3f}".format(dayfactor))