欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python菜鸟------天天向上的力量

程序员文章站 2022-05-18 07:55:13
...
  1. 一年365天,每天进步0.1%与每天后退0.1%.
>>> a = pow(1 + 0.001,365)
	print("{:.2f}".format(a))
结果:1.44
>>> a = pow(1 - 0.001,365)
	print("{:.2f}".format(a))
结果:0.69		#  颓废的人生到底有多可怕!!!
  1. 一年365天,一周5个工作日,每天进步1%
    一年365天,一周2个休息日,每天退步1%
>>> a = 1.0
	for i in range(365):
	    if i % 5 == 0 or i % 6 == 0:  # 周一开始
	        a *= (1 - 0.01)
	    else:
	        a *= (1 + 0.01)
	print("{:.2f}".format(a))
结果:3.36
>>> a = 1.0
	for i in range(365):
	    if i % 7 in [6,0]:			 #  周末开始
	        a *= (1 - 0.01)
	    else:
	        a *= (1 + 0.01)
	print("{:.2f}".format(a))
结果:4.63
  1. 365天,小峻每天进步1%不停歇,小铭每周工作5天休息2天,休息日下降1%.
    小铭在工作日要努力多少才能与小峻一样?
>>>	a = 1.0
	for i in range(365):
	    a *= 1.0 + 0.01
结果:37.78
b,dayup = 1.0,0.01
while b < a:
	b = 1.0
	dayup += 0.001
	for i in range(365):
		if i % 5 == 0 or i % 6 ==0 :	# 周一开始
		 	b *= (1 - 0.01)
		else:
			b *= (1 + dayup)
print("{:.3f}".format(dayup))
结果:0.021
b,dayup = 1.0,0.01
while b < a:
	b = 1.0
	dayup += 0.001
	for i in range(365):
		if i % 7 in [6,0]:		#  周末开始
			b *= (1 - 0.01)
		else:
			b *= (1 + dayup)
print("{:.3f}".format(dayup))
结果:0.019

从资料上看到利用函数写码:

def dayup(df):
    dayup = 1.0
    for i in range(365):
        if i % 7 in [6,0]:
            dayup *= (1 - 0.01)
        else:
            dayup *= (1 + df)
    return dayup
dayfactor = 0.001
while dayup(dayfactor) < 37.78:
    dayfactor += 0.001
print("工作日的努力参数是:{:.3f}".format(dayfactor))
结果:0.019
相关标签: python