用Python算带有进度条的圆周率
1 import time 2 scale=50 3 print("执行开始".center(scale//2,"-")) 4 start=time.perf_counter() 5 for i in range(scale+1): 6 a='*' *i 7 b='·' *(scale-i) 8 c=(i/scale)*100 9 dur=time.perf_counter()-start 10 print("\r{:3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur),end=" ") 11 time.sleep(0.1) 12 print("\n"+"执行结束".center(scale//2,"-"))