#计算公式:π/4=1-1/3+1/5-1/7+....... import math import time scale=100 #Π的精确读与scale的大小有关,越大越精确。 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)) time.sleep(0.1) Pi=k print("Pi值是{}".format(Pi)) print("\n"+"执行结束".center(scale//2,'-'))
Π的计算与文本进度条显示
猜你喜欢
转载自www.cnblogs.com/qq1294/p/12520151.html
今日推荐
周排行