python使用蒙特卡洛方法计算圆周率,python蒙特卡洛,蒙特卡洛方法计算圆周率,


蒙特卡洛方法计算圆周率,速度不快,准确率也不是很好,呵呵

[Python]代码

import randomcount = 1000000;incount = 0;for i in range(count) :    x = random.random()    y = random.random()    if (x**2 + y**2) < 1 :        incount+=1print(incount* 4.0 / count ) 

评论关闭