有进度条的圆周率
import math import time scale=50 s,m,=1,2 total,s,n,t=0.0,1,1.0,1.0 print("执行开始".center(scale//2, "#")) start = time.perf_counter() for i in range(scale+1): total+=t n+=2 s=-s t=s/n k=total*4 a = '*' * i b = '.' * (scale - i) c = (i/scale)*100 dur = time.perf_counter() - start print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur),end='') time.sleep(0.2) Pi=k print("Pi值是{}".format(Pi)) print("\n"+"执行结束".center(scale//2,'*'))

浙公网安备 33010602011771号