喂,老兄?如果需要其他评论/解释,请联系我:
一。x和n的人类语言声明:
设x为在给定时间检查的迭代次数。
设n为代码将在其上执行的迭代的倍数。
2。我们要做的是:
第一个代码块(块A)仅使用一个变量x(定义见上文),并使用5(整数)而不是变量n(定义见上文)。
第二个代码块(块B)同时使用上面定义的变量(x和n)。整数5将被变量n替换,因此,块B在第n次迭代时字面上执行操作。
我们的目标是每第X次迭代和每第5次/第N次迭代都做一些事情。
我们将经历100次迭代。
m、 易于理解的代码:
A区,最小变量: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.
B区,概括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.
请告诉我,如果你有任何问题,因为我没有时间测试后,写在这里。
三。练习如果你做得很好,看看你能不能把它和turtle.Pen()和turtle.forward()函数一起使用。
看看这个程序能否与turtle.circle()函数一起使用。
查看阅读(见下文),尝试改进练习1和练习2中的程序。