Python第二周
from tqdm import tqdm import time from random import random from math import sqrt DARTS=1000000 hits=0.0 time.clock() for i in range(1,DARTS): x,y=random(),random() ist=sqrt(x**2+y**2) if dist<=1.0: hits=hits+1 for i in tqdm(range(1,DARTS//100000+1)): time.sleep(0.05) pi=4*(hits/DARTS) print("Pi值是{}.".format(pi)) print("运行时间是:{:.5f}s".format(time.clock()))
有进度条的圆周率程序