- import random
- count = 1000000;
- incount = 0;
- for i in range(count) :
- x = random.random()
- y = random.random()
- if (x**2 + y**2) < 1 :
- incount+=1
- print(incount* 4.0 / count )
- #该片段来自于http://www.codesnippet.cn/detail/160420132843.html
来源: http://www.codesnippet.cn/detail/160420132843.html