python任务17带有进度条圆周率计算
带有进度条圆周率计算
from math import* import time n=10 pi=0.0 print("----执行开始----") start=time.perf_counter() for k in range(n+1): pi+=1/pow(16,k)*(4/(8*k+1)-2/(8*k+4)-1/(8*k+5)-1/(8*k+6)) a='*'*k b='.'*(n-k) c=(k/n)*100 dur=time.perf_counter() - start print("\r{:^3.0f}%[{}->{}]{:.2f}S".format(c,a,b,dur),end='\n') time.sleep(0.05) print("pi={:.10f}".format(pi)) print("----执行结束---")