In the first version of the checkerboard, you might have created a simple alternating pattern. In , the goal is usually to create a dynamic grid where the colors alternate both horizontally and vertically, regardless of the grid size.
This ensures that the starting character of each row alternates properly, preventing two rows from looking identical 0.5.2. 9.1.7 checkerboard v2 answers
Leo’s eyes widened. "So if the sum is odd, it inverts the starting color automatically." In the first version of the checkerboard, you
: The core feature of a checkerboard is that adjacent cells differ. Mathematically, you can determine which number to place by checking if the sum of the current indices is even or odd. (row + col) % 2 == 1 Otherwise, place a Row Construction : In each iteration of the outer loop, a current_row list is filled by the inner loop and then appended to : Finally, loop through Leo’s eyes widened
for row from 0 to 7: for col from 0 to 7: x = col * squareSize y = row * squareSize if (row + col) % 2 == 0: color = RED else: color = BLACK draw a square at (x, y) of size squareSize with fill color