Python蒙特卡洛方法求解圆周率

import random as r
times=eval(input())
r.seed(123)
counter=0
for i in range(times):
    x,y=r.random(),r.random()
    if pow(x,2)+pow(y,2)<=1:
        counter+=1
print('{:.6f}'.format(4*counter/times))

你可能感兴趣的:(python,开发语言)