求pi

import random
S =20e6
N = 0
for i in range(int(S)):
x = random.random()
y = random.random()
d = (x-0.5)**2+(y-0.5)**2
if d<=0.5**2: N+=1
else:
pass
PI = 4*N/S
print(PI)
print("3105")

 

 

posted @ 2023-10-31 23:44  一只蜗牛hhhh  阅读(11)  评论(0编辑  收藏  举报