一:
import time
import random
def progress_bar():
for i in range(1, 300):
print("Download progress: {}%: ".format(i), "▋" * (i // 2), f'{i}/100')
time.sleep(random.random())
if __name__ == '__main__':
progress_bar()
二:
import sys
import time
def progress_bar():
for i in range(1, 101):
print("\r", end="")
print("Download progress: {}%: ".format(i), "▋" * (i // 2), end="")
sys.stdout.flush()
time.sleep(0.05)
if __name__ == '__main__':
progress_bar()
三(带时间):
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("\n"+"执行结束,万幸".center(scale // 2,"-"))
|