<p>喂,老兄?如果需要其他评论/解释,请联系我:</p>
<h2>一。<code>x</code>和<code>n</code>的人类语言声明:</h2>
<p>设x为在给定时间检查的迭代次数。
设n为代码将在其上执行的迭代的倍数。</p>
<h2>2。我们要做的是:</h2>
<p><strong>第一个代码块(块A)</strong>仅使用一个变量x(定义见上文),并使用5(整数)而不是变量n(定义见上文)。</p>
<p><strong>第二个代码块(块B)</strong>同时使用上面定义的变量(x和n)。整数5将被变量n替换,因此,<strong>块B在第n次迭代时字面上执行操作。</p>
<p>我们的目标是每第X次迭代和每第5次/第N次迭代都做一些事情。
我们将经历100次迭代。</p>
<h2>m、 易于理解的代码:</h2>
<h2>A区,最小变量:</h2>
<pre><code>for x in 100:
#what to do every time (100 times): replace this line with your every-iteration functions.
if x % 5 == 0:
#what to do every 5th time: replace this line with your nth-iteration functions.
</code></pre>
<h2>B区,概括</h2>
<pre><code>n = 5
for x in 100:
#what to do every time (100 times): replace this line with your every-iteration functions.
if x % n == 0:
#what to do every 5th time: replace this line with your nth-iteration functions.
</code></pre>
<p>请告诉我,如果你有任何问题,因为我没有时间测试后,写在这里。</p>
<h2>三。练习</h2>
<ol>
<li>如果你做得很好,看看你能不能把它和turtle.Pen()和turtle.forward()函数一起使用。</li>
<li>看看这个程序能否与turtle.circle()函数一起使用。</li>
<li>查看阅读(见下文),尝试改进练习1和练习2中的程序。</li>
</ol>
<p>关于模和其他基本运算符:
<a href="https://docs.python.org/2/library/stdtypes.html" rel="nofollow noreferrer">https://docs.python.org/2/library/stdtypes.html</a>
<a href="http://www.tutorialspoint.com/python/python_basic_operators.htm" rel="nofollow noreferrer">http://www.tutorialspoint.com/python/python_basic_operators.htm</a></p>
<p>关于海龟:
<a href="https://docs.python.org/2/library/turtle.html" rel="nofollow noreferrer">https://docs.python.org/2/library/turtle.html</a>
<a href="https://michael0x2a.com/blog/turtle-examples" rel="nofollow noreferrer">https://michael0x2a.com/blog/turtle-examples</a></p>