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("----执行结束---")

posted @ 2020-03-22 16:43  猪小叶  阅读(202)  评论(0编辑  收藏  举报