V1 Codehs Fixed //top\\ | 916 Checkerboard

A standard checkerboard relies on an alternating pattern. In a 2D grid, every cell can be identified by its row index ( ) and its column index (

def create_checkerboard(rows, cols): # Initialize an empty list to hold our 2D grid board = [] # Loop through each row for i in range(rows): # Create an empty row row = [] # Loop through each column in the row for j in range(cols): # Check if the sum of the indices is even if (i + j) % 2 == 0: row.append(1) else: row.append(0) # Add the completed row to the board board.append(row) return board # -- Code provided by CodeHS to print the board neatly -- def print_board(board): for row in board: print(" ".join([str(x) for x in row])) # Example Usage: my_board = create_checkerboard(8, 8) print_board(my_board) Use code with caution. Common Errors to Avoid

# Draw the square fill(fill_color) rect(col * square_size, row * square_size, square_size, square_size)

board = [] # 1. Initialize an empty list for row in range(8): # 2. Outer loop for each of the 8 rows new_row = [] # 3. Create a new row list for col in range(8): # 4. Inner loop for the 8 columns if (row < 3 or row > 4): # 5. Check if we are in the top or bottom 3 rows # 6. Add a 1 if the sum of row and col is even, otherwise add a 0 new_row.append(1 if (row + col) % 2 == 0 else 0) else: new_row.append(0) # 7. For middle rows, add only zeros board.append(new_row) # 8. Append the completed row to the board

If the sum of the row and column is (i + j = odd), you place a 0. 916 checkerboard v1 codehs fixed

Your primary helper function needs to handle moving across a row while dropping balls every second space. javascript

Before looking at the fixed code, it is vital to understand the mathematical pattern behind a checkerboard.

: Ensure canvas dimensions are evenly divisible by the number of squares:

Using <= instead of < in your loop conditions often causes the program to draw an extra row or column off-screen. This fails the CodeHS internal test cases, which strictly validate the total number of shape objects added to the canvas. The Logical Fix: Row plus Column Check A standard checkerboard relies on an alternating pattern

The system wants to see you access a specific spot in a 2D list (e.g., board[i][j] = 1 The Solution: Step-by-Step Fix

Now that you've mastered the basic grid, are you ready to tackle Checkerboard v2 and add more complex patterns?

# Draw the square no_stroke() rect(col * square_size, row * square_size, square_size, square_size)

This public link is valid for 7 days and shares a thread, including any personal information you added. This link or copies made by others cannot be deleted. If you share with third parties, their policies apply. Can’t copy the link right now. Try again later. Initialize an empty list for row in range(8): # 2

You need an outer loop for rows and an inner loop for columns.

If you are still hitting roadblocks with your CodeHS compiler, let me know:

(leftIsClear()) turnLeft(); move(); turnLeft();

: Karel checks if there is room to move again before placing the next beeper. This prevents errors on narrow boards. 3. The repositionToNextRow() Function