Python 文本进度条
程序员文章站
2024-02-24 13:31:34
...
题目链接:
https://python123.io/student/courses/5028/groups/64412/problems/programmings/6881#pagetop
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
# 下面的 \r 是回车键,将命令行的光标移动到所在行的开头,这样就实现了覆盖效果
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c, a, b, dur), end='')
time.sleep(0.1)
print("\n" + "执行结束".center(scale // 2, '-'))