9.1.7 Checkerboard V2 Codehs Official
Define or use a function to print each row of the list so it looks like a grid.
As discussed on Reddit , simply printing the pattern isn't enough for V2. We must interact with the array structure.
def board(): myGrid = [] # Track index bounds up to an 8-row layout for i in range(8): # If the row index is even, start the line pattern with 0 if i % 2 == 0: myGrid.append([0, 1] * 4) # If the row index is odd, start the line pattern with 1 else: myGrid.append([1, 0] * 4) # Print out each nested row list systematically for i in range(8): print(myGrid[i]) board() Use code with caution. Troubleshooting Guide & Validation Checklist
private static final int NUM_ROWS = 8; private static final int NUM_COLS = 8; 9.1.7 Checkerboard V2 Codehs
The trick to a checkerboard is the condition if (i + j) % 2 == 0 .
The color should depend on whether the sum of the row and column index is even or odd ( (row + col) % 2 == 0 ). 3. Coordinate System
If (row + column) % 2 == 0 → Color A. If (row + column) % 2 == 1 → Color B. Define or use a function to print each
(even vs. odd). By tracking the current row number and column number, the program can decide whether to place a marker based on the following rule: If the sum of the (Row + Column) is , place a beeper. If the sum is , leave the space empty.
. This exercise is a pivotal moment for students learning Java or JavaScript (Karel), as it transitions from simple movement to complex nested loops and conditional logic. The Objective
The final printed output must form an alternating pattern where adjacent cells horizontally and vertically do not share the same value: def board(): myGrid = [] # Track index
Nested Loops, If/Else Statements, Coordinate Geometry, Color Management.
To meet all testing constraints of the platform, the logic is separated into three systematic tasks:
System.out.println(); // new line after each row