9.1.7 Checkerboard V2 Codehs Patched
Whether you are printing text to the console or drawing colored rectangles on a canvas, the logic remains identical. Write your code to be flexible (no magic numbers), test edge cases (1 row or 1 column), and always double-check your starting color.
# 1. Initialize an 8x8 grid filled with 0s board = [] for i in range(8): board.append([0] * 8) # 2. Use nested loops to assign 1s in a checkerboard pattern for i in range(8): # Loop through rows for j in range(8): # Loop through columns # If the sum of indices is even, set to 1 if (i + j) % 2 == 0: board[i][j] = 1 # 3. Print the board to verify for row in board: print(row) Use code with caution. Copied to clipboard 🔍 Why it Works: The "Parity" Rule 9.1.7 Checkerboard V2 Codehs
This approach ensures that adjacent squares have different colors, resulting in the characteristic checkerboard pattern. Whether you are printing text to the console
Beyond passing the autograder, this exercise teaches: Initialize an 8x8 grid filled with 0s board
if (row + col) % 2 == 0: pen.color("red") else: pen.color("black")
