import turtle
turtle.color('red','red')
turtle.begin_fill()for i inrange(5):
turtle.fd(200)
turtle.rt(144)
turtle.end_fill()
turtle.done()
三、温度转化
#温度转换.py'''温度转换.py'''
TempStr =input('请输入带有符号的温度值:')if TempStr[-1]in['F','f']:
C =(eval(TempStr[0:-1])-32)/18print('转换后的温度时{:.2f}C'.format(C))elif TempStr[-1]in['C','c']:
F =1.8*eval(TempStr[0:-1])+32print('转换后的温度时{:.2f}F'.format(F))else:print('输入格式有误')
四、天天向上的力量
#天天向上的力量defdayUP(df):#定义一个函数
dayup =1for i inrange(365):#0--364if i %7in[6,0]:
dayup *=(1-0.01)else:
dayup *=(1+ df)return dayup
dayfactor =0.01while dayUP(dayfactor)<37.78:
dayfactor +=0.001print('工作日的努力参数是:{:.3f}'.format(dayfactor))
"""文本进度条
最终版
"""import time
scale =50print('开始执行'.center(scale//2,'-'))#居中,宽度25
start = time.perf_counter()#记录开始时间for i inrange(scale+1):
a ='*'* i
b ='.'*(scale - i)
c = i / scale *100
dur = time.perf_counter()- start#计算时差print('\r{:^3.0f}%[{}->{}]{:.2f}s'.format(c,a,b,dur),end ='')#/r 表示从该行的行首开始刷新,
time.sleep(0.05)print('\n'+'结束'.center(scale//2,'-'))-----------开始执行----------100%[**************************************************->]2.53s
------------结束-----------