V2 Answers | 9.1.7 Checkerboard
Leo turned back to his keyboard. He highlighted his clumsy logic: if (j % 2 == 0)
# Check if the sum of indices is odd or even to alternate colors (row + col) % : current_row.append( : current_row.append( # Add the completed row to the grid my_grid.append(current_row) # Print each row to display the board my_grid: print(row) # Call the function to execute Use code with caution. Copied to clipboard Key Logic Steps Initialize the Grid : Start by creating an empty list, , which will eventually hold eight separate row lists. Nested Loops : Use a outer loop to iterate through 8 rows and an inner loop to iterate through 8 columns. Alternating Pattern Logic 9.1.7 checkerboard v2 answers
If the user resizes the window, you want the board to redraw. Override the init() method to add a resize listener or simply set the canvas size to be fixed using setSize(400, 400) in the constructor. Leo turned back to his keyboard
for row in range(5, 8): for col in range(8): if (row + col) % 2 != 0: board[row][col] = Checker('white') return board Nested Loops : Use a outer loop to