擅长:python、mysql、java
<p>你的错误就在你的计划快结束的时候。在</p>
<pre><code>while i in range(0, size) or e in range(0, size):
t_step = randint(1, 5)
t.forward(t_step)
i = i + t_step
r_step = randint(1, 5)
r.forward(r_step)
e = e + r_step
</code></pre>
<p>在这样一个场景中,假设i=298,并且t_step选择一个随机整数作为3。乌龟最终会移动超过300的范围,因此它会离开牵引箱。<strong>循环不会停止,因为它只意识到当所有代码都已运行时i超出范围。(也就是说,当循环被打破时,乌龟已经离开了盒子。)</strong>这就是为什么乌龟会走出盒子。你可以试着用一个“如果”条件来防止这种情况发生。在</p>