【python基础操作实例】(4)——文本进度条、天天向上

文本进度条

##文本记录条V1
import time
scale = 10
print("------执行开始------")
for i in range(scale+1):
    a='*'*i
    b='.'*(scale-i)
    c=(i/scale)*100
    print("{:^3.0f}%[{}->{}]".format(c,a,b))
    time.sleep(0.1)
print("------执行结束------")
##文本记录条V2
import time
for i in range(101):
    print("\{:3}%".format(i),end="")
    time.sleep(0.1)
##文本记录条V3  [^1]
import time
scale = 50
print("执行开始".center(scale//2,"-"))
start=time.perf_counter()
for i in range(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='')
    time.sleep(0.1)
print("执行结束".center(scale//2,"-"))

[^1] : V3要在cmd命令指示符下运行

天天向上

##天天向上
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.78:
    dayfactor += 0.001
print("工作日的努力参数是:{:.3f}".format(dayfactor))
        

你可能感兴趣的:(Python基础学习笔记)