import time scale=100 print("执行开始".center(scale+28,'-')) start = time.perf_counter() for i in range(scale+1): a = '*' * i b = '.' * (scale - i) c = (i/scale)*100 t = time.perf_counter() - start print("\r任务进度:{:>3.0f}% [{}->{}]消耗时间:{:.2f}s".format(c,a,b,t),end="") time.sleep(0.03) print("\n"+"执行结束".center(scale+28,'-'))
执行结果:
--------------------------------------------------------------执行开始-------------------------------------------------------------- 任务进度:100% [****************************************************************************************************->]消耗时间:3.26s --------------------------------------------------------------执行结束--------------------------------------------------------------