import random
import math
import time
s = eval(input("请输入取点总数:"))
hits = 0.0
start = time.perf_counter()
for i in range(s):
x,y = random.random(),random.random()
dist = math.sqrt(x**2 + y**2)
if dist <= 1.0:
hits += 1
else:
continue
pi = hits/s*4
t = time.perf_counter() - start
print("pi是{0},运行时间是{1:5.5f}s".format(pi,t))
import math
import time
s = eval(input("请输入取点总数:"))
hits = 0.0
start = time.perf_counter()
for i in range(s):
x,y = random.random(),random.random()
dist = math.sqrt(x**2 + y**2)
if dist <= 1.0:
hits += 1
else:
continue
pi = hits/s*4
t = time.perf_counter() - start
print("pi是{0},运行时间是{1:5.5f}s".format(pi,t))