首页 > 其他分享 >求π

求π

时间:2023-10-30 12:33:05浏览次数:20  
标签: __ monte int random count num

import random

def monte_carlo_pi(num):
count = 0
for i in range(num):
x, y = random.uniform(-1, 1), random.uniform(-1, 1)
if x**2 + y**2 <= 1:
count += 1
return 4 * count / num

if __name__ == '__main__':
sd = int(input())
random.seed(sd)
times = int(input())
print(monte_carlo_pi(times))

标签:,__,monte,int,random,count,num
From: https://www.cnblogs.com/ywo-/p/17797554.html

相关文章