Python语言程序设计基础(第2版) 课后题 第三章
程序员文章站
2024-02-02 15:03:40
...
#3.1
import math
dayup=math.pow((1.0+0.001),365)
daydown=math.pow((1.0-0.001),365)
print("向上:{:.2f},向下:{:.2f}.".format(dayup,daydown))
向上:1.44,向下:0.69.
#3.2
import math
dayup=math.pow((1.0+0.005),365)
daydown=math.pow((1.0-0.005),365)
print("向上:{:.2f},向下:{:.2f}.".format(dayup,daydown))
向上:6.17,向下:0.16.
#3.3
import math
dayfactor=0.01
dayup=math.pow((1.0+dayfactor),365)
daydown=math.pow((1.0-dayfactor),365)
print("向上:{:.2f},向下:{:.2f}.".format(dayup,daydown))
向上:37.78,向下:0.03.
#3.4
dayup,dayfactor=1.0,0.01
for i in range(365):
if i % 7 in [6,0]:
dayup=dayup*(1-dayfactor)
else:
dayup=dayup*(1+dayfactor)
print("向上5天向下2天的力量:{:.2f}".format(dayup))
向上5天向下2天的力量:4.63
#3.5
def dayUp(df):
dayup=1.0
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.78):
dayfactor+=0.001
print("每天努力的参数是:{:.3f}.".format(dayfactor))
每天努力的参数是:0.019.
#3.1
def wightChange(w):
for i in range(10):
w_h=w*0.165
print("第{:^3}年,你的月球体重是{:.2f}".format((i+1),w_h))
w+=0.5
wight=input("请输入你的地球体重:")
wightChange(eval(wight))
请输入你的地球体重:22
第 1 年,你的月球体重是3.63
第 2 年,你的月球体重是3.71
第 3 年,你的月球体重是3.80
第 4 年,你的月球体重是3.88
第 5 年,你的月球体重是3.96
第 6 年,你的月球体重是4.04
第 7 年,你的月球体重是4.12
第 8 年,你的月球体重是4.21
第 9 年,你的月球体重是4.29
第10 年,你的月球体重是4.37
#3.2
day = 0
week = 0
dayup = 1
for i in range(365):
day = day + 1
week = week + 1
if week <= 3:
dayup=dayup
elif week < 7 and week >= 4:
dayup = dayup*(1+0.01)
elif week == 7:
dayup=dayup*(1+0.01)
week = 0
print("连续学习365天后能力值是:{}".format(dayup))
连续学习365天后能力值是:7.922198989348805
#3.3.1
dayup = 1
dayfactor = 0.01
period = [4,5,6,0]
decrease = 0
for j in range(1,366):
temp = j - decrease
tom = temp % 7
if j%10 == 0:
decrease += j - (tom - 1)
tom = 1
if tom in period:
dayup = dayup * (1 + dayfactor)
print('每10天休息一次后是{}'.format(dayup))
每10天休息一次后是6.557520318378848
#3.3.2
dayup = 1
dayfactor = 0.01
period = [4,5,6,0]
decrease = 0
for j in range(1,366):
temp = j - decrease
tom = temp % 7
if j%15 == 0:
decrease += j - (tom - 1)
tom = 1
if tom in period:
dayup = dayup * (1 + dayfactor)
print('每15天休息一次后是{}'.format(dayup))
每15天休息一次后是7.03054935549398
#3.4
number=input("请输入一个五位数:")
if len(number)==5:
if eval(number)==eval(number[-1:]+number[3:4]+number[2:3]+number[1:2]+number[0:1]):
print("这是回文数")
else:
print("这不是一个回文数")
请输入一个五位数:56655
这不是一个回文数
for i in range(11):
if i in [0,5,10]:
print("+ - - - - + - - - - +")
else:
print("| | |")
+ - - - - + - - - - +
| | |
| | |
| | |
| | |
+ - - - - + - - - - +
| | |
| | |
| | |
| | |
+ - - - - + - - - - +
#3.7
while True:
for i in ["/","-","|","\\","|"]:
print("%s\r"%i,end='')
-会是一个一直选择的一条杠,这里不好展示
#3.8
from tqdm import tqdm
from time import sleep
for i in tqdm(range(1,100)):
sleep(0.01)
100%|██████████████████████████████████████████████████████████████████████████████████| 99/99 [00:01<00:00, 84.59it/s]
上一篇: M-H Python实现