文本进度条(2)

代码(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()
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur),end="")
time.sleep(0.1)
print("\n"+"执行结束".center(scale//2,"-"))

输出:
-----------执行开始----------
100%[**************************************************->]6201.12s
-----------执行结束----------

代码(2)如下:
import time
scale = 50
print("执行开始".center(scale,"-"))
start = time.perf_counter()
for i in range(scale+1):
a=""i
b="."(scale-i)
c=(i/scale)
100
dur = time.perf_counter()
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur))
time.sleep(0.1)
print("\n"+"执行结束".center(scale,"-"))

输出:
-----------------------执行开始-----------------------
0 %[->..................................................]6773.77s
2 %[->.................................................]6773.87s
4 %[
->................................................]6773.97s
6 %[
**->...............................................]6774.07s
8 %[****->..............................................]6774.17s
10 %[*****->.............................................]6774.27s
12 %[******->............................................]6774.37s
14 %[*******->...........................................]6774.48s
16 %[********->..........................................]6774.58s
18 %[*********->.........................................]6774.68s
20 %[**********->........................................]6774.78s
22 %[***********->.......................................]6774.88s
24 %[************->......................................]6774.98s
26 %[*************->.....................................]6775.08s
28 %[**************->....................................]6775.18s
30 %[***************->...................................]6775.28s
32 %[****************->..................................]6775.38s
34 %[*****************->.................................]6775.49s
36 %[******************->................................]6775.59s
38 %[*******************->...............................]6775.69s
40 %[********************->..............................]6775.79s
42 %[*********************->.............................]6775.89s
44 %[**********************->............................]6775.99s
46 %[***********************->...........................]6776.09s
48 %[************************->..........................]6776.19s
50 %[*************************->.........................]6776.29s
52 %[**************************->........................]6776.39s
54 %[***************************->.......................]6776.49s
56 %[****************************->......................]6776.59s
58 %[*****************************->.....................]6776.70s
60 %[******************************->....................]6776.80s
62 %[*******************************->...................]6776.90s
64 %[********************************->..................]6777.00s
66 %[*********************************->.................]6777.10s
68 %[**********************************->................]6777.20s
70 %[***********************************->...............]6777.30s
72 %[************************************->..............]6777.40s
74 %[*************************************->.............]6777.50s
76 %[**************************************->............]6777.60s
78 %[***************************************->...........]6777.70s
80 %[****************************************->..........]6777.81s
82 %[*****************************************->.........]6777.91s
84 %[******************************************->........]6778.01s
86 %[*******************************************->.......]6778.11s
88 %[********************************************->......]6778.21s
90 %[*********************************************->.....]6778.31s
92 %[**********************************************->....]6778.41s
94 %[***********************************************->...]6778.51s
96 %[************************************************->..]6778.61s
98 %[*************************************************->.]6778.71s
100%[**************************************************->]6778.81s

-----------------------执行结束-----------------------

代码为本人亲自敲写,都可以运行,转载的朋友请注明出处https://www.jianshu.com/writer#/notebooks/35294278/notes/43542407,谢谢!

你可能感兴趣的:(文本进度条(2))