is an exercise from the Python curriculum on the CodeHS platform. Its goal is to build a foundational piece of a larger checkers game by constructing a program to represent the game board using numbers. In this simulation, a 1 stands for a checker piece, and a 0 represents an empty square.
The vertical position depends on the current row index r . This shifts the drawing pen downward every time the outer loop advances.
Here is the complete Python solution that passes the CodeHS requirements.
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 9.1.6 checkerboard v1 codehs
The most common mistake is simply "cheating" the output with a print statement. The CodeHS autograder specifically checks for (e.g., board[i][j] = 1 ). If you don't use these, you'll see a red error message: "You should set some elements of your board to 1." .
To successfully complete this exercise, you must understand the following Python concepts:
Alternatively, you can think of it as: if the row is even, start with color A; if the row is odd, start with color B. The Code Implementation (Java/CodeHS Style) is an exercise from the Python curriculum on
# Create an 8x8 grid of zeros board = [] for i in range(8): board.append([0] * 8) Use code with caution. Copied to clipboard 2. Apply the Checkerboard Logic
Do you need help adapting this logic into a (like Checkerboard v2)?
# Function to print the board in a readable format def print_board(board): for row in board: print(" ".join(str(cell) for cell in row)) The vertical position depends on the current row index r
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
Once you've mastered "Checkerboard, v1," you can challenge yourself further:
Here is a standard way to write the program:
B . B . B . B . B . B . B . B . B . B . B . B . B