<<--B站..........欢迎来到DGX的博客..........GitHub-->>

我的B站

有进度条的圆周率计算

 1 from random import random
 2 from time import perf_counter
 3 from tqdm import tqdm
 4 import time
 5 for i in tqdm(range(100)):
 6     time.sleep(0.1)
 7     print("\n")
 8 DARTS = 1000 * 1000
 9 hits = 0.0
10 start = perf_counter()
11 for i in range(1,DARTS+1):
12     x,y = random(),random()
13     dist = pow(x ** 2 + y ** 2,0.5)
14     if dist <= 1.0:
15         hits = hits + 1
16 pi = 4 * (hits / DARTS)
17 print("圆周率值是:{}".format(pi))
18 print("运行时间是:{:.5f}s".format(perf_counter() - start))

 

posted @ 2020-04-15 15:23  DG息  阅读(205)  评论(0)    收藏  举报