9.1.6 Checkerboard — V1 Codehs
for i in range(8): # Loop through rows for j in range(8): # Loop through columns # Logic goes here Use code with caution. Step 3: Apply the Checkerboard Logic Inside the loops, you need to decide when to put a
(B = beeper, . = empty)
Some versions of the CodeHS exercise use red instead of gray. If your prompt says "red and black", simply change the color in the conditional:
for i in range(8): row = [] for j in range(8): if (i + j) % 2 == 0: row.append("R") # R for red else: row.append("B") # B for black board.append(row) 9.1.6 checkerboard v1 codehs
: Check if the row index is in the top three (0, 1, 2) or the bottom three (5, 6, 7). If it is, change those elements to 1 .
: If the sum leaves a remainder, it colors the square white . Visual Example Matrix (Row + Col) : Top-Left cell (0,0) : →right arrow Next cell right (0,1) : →right arrow First cell second row (1,0) : →right arrow Second cell second row (1,1) : →right arrow 3. Calculating Coordinates
Implementing a grid-based graphics program is a classic milestone in learning computer science. In the CodeHS JavaScript Graphics curriculum, the assignment challenges you to combine loops, nested structures, and geometric math to draw a classic checkerboard pattern on the screen. for i in range(8): # Loop through rows
The top-left square is black instead of gray. Fix: Ensure your parity logic starts with (row + col) % 2 == 0 as gray. If it's reversed, swap the colors in the if statement.
To successfully complete this exercise, you must understand the following Python concepts:
Here is the standard JavaScript / Canvas implementation used in the CodeHS Karel/Graphics environment: javascript If your prompt says "red and black", simply
while (frontIsClear()) move(); if (startWithBeeper) // Alternate pattern: after moving, we want opposite // Better approach: move, then if column index is even/odd // But simpler: use a counter
Finally, you must print the board to match the CodeHS output requirements. 4. The Final Code: 9.1.6 Checkerboard V1
board = []