擅长:python、mysql、java
<p>下面两行应该进入for循环。在每个线索,它需要有2个随机数,这是不同于以往。你知道吗</p>
<pre><code>x_value = random.random()
y_value = random.random()
</code></pre>
<p>因此,代码应该如下所示。你知道吗</p>
<pre><code>import random
random.seed(1000)
# print(x_value)
# print(y_value)
pointsInCircle= 0
numberOfTrials = 1000
for trials in range(numberOfTrials):
x_value = random.random()
y_value = random.random()
if 1 > ((x_value ** 2) + (y_value ** 2)):
pointsInCircle = pointsInCircle + 1
else:
print("No estimation possbile")
pi = 4 * (pointsInCircle/numberOfTrials)
print(pi)
</code></pre>
<p>从而得到答案<code>3.02</code>。你知道吗</p>