#pi.py
import random
import time
count = 0
start = time.perf_counter()
for i in range(0,10**6):
x = random.uniform(-1,1)
y = random.uniform(-1,1)
if (x*x + y*y)**(1/2) < 1:
count=count+1
pi = (4*count/10**6)
print("frequency:",10**6)
print("pi = {:.5f}".format(pi))
print("time: {:.5f}s".format(time.perf_counter()-start))
标签:count,10,pi,python,圆周率,random,time,print,PI From: https://www.cnblogs.com/ayablog/p/16787814.html