1 import math 2 import time 3 scale=20 4 s,m,=1,2 5 total,s,n,t=0.0,1,1.0,1.0 6 print("执行开始".center(scale//2, "-")) 7 start = time.perf_counter() 8 for i in range(scale+1): 9 total+=t 10 n+=2 11 s=-s 12 t=s/n 13 k=total*4 14 a = '*' * i 15 b = '.' * (scale - i) 16 c = (i/scale)*100 17 dur = time.perf_counter() - start 18 print(" {:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur)) 19 time.sleep(0.1) 20 Pi=k 21 print("Pi值是{}".format(Pi)) 22 print(" "+"执行结束".center(scale//2,'-'))
进度条覆盖进行:
1 import math 2 import time 3 scale=50 4 s,m,=1,2 5 total,s,n,t=0.0,1,1.0,1.0 6 print("执行开始".center(scale//2, "-")) 7 start = time.perf_counter() 8 for i in range(scale+1): 9 total+=t 10 n+=2 11 s=-s 12 t=s/n 13 k=total*4 14 a = '*' * i 15 b = '.' * (scale - i) 16 c = (i/scale)*100 17 dur = time.perf_counter() - start 18 print(" {:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur),end='') 19 time.sleep(0.1) 20 Pi=k 21 print("Pi值是{}".format(Pi)) 22 print(" "+"执行结束".center(scale//2,'-'))