9.1.6 Checkerboard V1 Codehs !!top!! Direct

The CodeHS exercise is a classic coding problem designed to teach logic, loops, and data structures. By breaking it down step-by-step and understanding the role of the condition row < 3 or row > 4 and the pattern generator (row + column) % 2 , you can easily build and visualize the checkerboard. Mastering this foundational exercise is a great step toward building more complex logic for an interactive checkers game.

: If you get a red mark saying "You should set some elements of your board to 1," ensure you are actually modifying or appending values to the list, not just printing text that looks like a grid. Function Placement : Always define your print_board function at the top of your script to avoid scope errors. for version 2 of this exercise?

Ensure your loops run from 0 to NUM_ROWS - 1 . Using <= instead of < will often result in the board drawing off the screen. 9.1.6 checkerboard v1 codehs

⚠️ Some CodeHS courses include a related exercise, "1.17.6: Checkerboard Karel," which involves using Karel the Dog to paint a checkerboard pattern by moving and placing beepers. However, the 9.1.6 exercise is specifically about creating a 2D list data structure in Python.

Text (console) output — using characters: The CodeHS exercise is a classic coding problem

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)

The core challenge is making the colors alternate. If you simply alternate every time a square is drawn, the rows will align vertically, creating vertical stripes instead of a checkerboard. : If you get a red mark saying

# Function to print the board in the required format def print_board(board): for row in board: # Join the numbers with a space print(" ".join(map(str, row))) def main(): # 1. Initialize an empty board with 8 rows and 8 columns of zeros board = [] for i in range(8): board.append([0] * 8) # 2. Modify the board: Set specific elements to 1 # Example logic: Make top 3 rows all 1s for row in range(3): for col in range(8): board[row][col] = 1 # Alternatively, you can fill the whole board with a checkerboard # or specific pattern, but 3 rows of 1s is a common requirement. # 3. Print the resulting board print_board(board) main() Use code with caution. 4. Key Takeaways for Success A. List Initialization

Hardcoding the size of the squares is a common mistake. CodeHS provides the canvas width and height globally via getWidth() and getHeight() . Because a checkerboard is a perfect square grid, you calculate the size of a single square like this: javascript

A function to handle the transition from one row to the next.