【发布时间】:2013-04-09 22:53:28
【问题描述】:
我知道答案应该是我的坐标的大约 60% 在这个范围内,但我只得到大约 20%
import random
import pylab
import numpy
pylab.close("all") #all import statements
x = [(random.randint(0,100)) for i in range(3000)] #creating list of x coordinates
y = [(random.randint(0,100)) for j in range(3000)] #creating list of y coordinates
array=zip(x,y) #creating an array by combining the x and y coordinates
counter = 0
for i, j in array:
if 35**2 <= (i**2+j**2) <= 65**2:
counter+= 1
print counter
谁能告诉我我做错了什么?
【问题讨论】:
-
你怎么知道你是否使用随机数?
-
在这么大的样本上,仅通过查看该区域就应该接近 60%
标签: python arrays loops counter