【发布时间】:2016-06-03 01:52:03
【问题描述】:
我正在尝试使用海龟图形绘制棋盘,但我不知道如何循环遍历所有其他方格以将其涂黑
for each_row in range(number_of_rows):
for each_column in range(number_of_columns):
if (each_column % 2) ==0: #this is the line that's doubtful
draw_black_box()
else:
draw_white_box()
goto_next_box_pos()
goto_next_row_pos()
框的绘制工作得很好,但我觉得我循环错了。
现有函数 goto_next_box_pos() 负责将海龟重新定位到要绘制行中下一个框的位置。现有函数 goto_next_row_pos() 负责将海龟重新定位到要绘制下一行的位置。
【问题讨论】:
-
这是一种非常合理的代码结构方式。
-
好的,但是在第 3 行,我应该输入>> if (each_row % 2) ==0: 代替吗?还是这样好吗