擅长:python、mysql、java
<p>试试这个。你的代码应该是while循环的一部分。如果不是,请将<code>out_of_layer</code>移到下一个外循环之前。在</p>
<pre><code>out_of_layer = False
while math.sqrt((pho.pos.x)*(pho.pos.x)+(pho.pos.y)*(pho.pos.y)+(pho.pos.z)*(pho.pos.z))<10:
x=random.uniform(-j,j)
... blah blah stuff you already know about ...
d=math.sqrt((pho.pos.x)*(pho.pos.x)+(pho.pos.y)*(pho.pos.y)+(pho.pos.z)*(pho.pos.z))
if not out_of_layer:
print pho.pos
print d
print 'Out of Layer 1 in',t,'steps!'
out_of_layer = True
</code></pre>