9.1.7 Checkerboard V2 Codehs Work
: Avoid manually typing out all 64 values. The exercise is designed to test your mastery of loops. specific error message you're seeing, or should we walk through the print_board function
Ensure your loops start at 0 and use the strictly less-than operator ( < NUM_ROWS ). Starting at 1 or using <= will push squares off the screen.
Mastering CodeHS 9.1.7 Checkerboard V2: A Comprehensive Guide
function drawSquare(x, y, color) var rect = new Rectangle(SQUARE_SIZE, SQUARE_SIZE); rect.setPosition(x, y); rect.setColor(color); add(rect); Use code with caution. Step 3: Build the Nested Loop Logic 9.1.7 Checkerboard V2 Codehs
First, ensure you know the dimensions of the grid. CodeHS usually provides constants or variables for the number of rows and columns (e.g., grid.length for rows and grid[0].length for columns). Step 2: Set Up Nested Loops
Ensure all loop tasks are cleanly indented with standard 4-space gaps.
This approach ensures that adjacent squares have different colors, resulting in the characteristic checkerboard pattern. : Avoid manually typing out all 64 values
The autograder often checks if you actually changed the values in the list using my_grid[row][col] = 1 . Simply printing a pattern without updating the list will likely cause the test to fail.
Use one loop to iterate through each row (0-7) and a nested loop to iterate through each column (0-7).
In the previous version, you might have simply alternated colors in a single line. In V2, you are creating a full 2D grid. The "checkerboard logic" relies on a simple mathematical truth: if you add the row index and the column index together, even sums get one color, and odd sums get the other. Breaking Down the Logic Step 3: Build the Nested Loop Logic First,
When designing the Checkerboard V2, students must consider several key factors:
def print_board(board): for i in range(len(board)): # Joins the list elements into a single string for printing print(" ".join([str(x) for x in board[i]])) # 1. Initialize an 8x8 grid filled with 0s my_grid = [] for i in range(8): my_grid.append([0] * 8) # 2. Use nested loops to assign 1s in a checkerboard pattern for row in range(8): for col in range(8): # 3. Check if the sum of indices is odd or even if (row + col) % 2 != 0: my_grid[row][col] = 1 # 4. Print the final result print_board(my_grid) Use code with caution. Common Pitfalls
: Avoid manually typing out all 64 values. The exercise is designed to test your mastery of loops. specific error message you're seeing, or should we walk through the print_board function
Ensure your loops start at 0 and use the strictly less-than operator ( < NUM_ROWS ). Starting at 1 or using <= will push squares off the screen.
Mastering CodeHS 9.1.7 Checkerboard V2: A Comprehensive Guide
function drawSquare(x, y, color) var rect = new Rectangle(SQUARE_SIZE, SQUARE_SIZE); rect.setPosition(x, y); rect.setColor(color); add(rect); Use code with caution. Step 3: Build the Nested Loop Logic
First, ensure you know the dimensions of the grid. CodeHS usually provides constants or variables for the number of rows and columns (e.g., grid.length for rows and grid[0].length for columns). Step 2: Set Up Nested Loops
Ensure all loop tasks are cleanly indented with standard 4-space gaps.
This approach ensures that adjacent squares have different colors, resulting in the characteristic checkerboard pattern.
The autograder often checks if you actually changed the values in the list using my_grid[row][col] = 1 . Simply printing a pattern without updating the list will likely cause the test to fail.
Use one loop to iterate through each row (0-7) and a nested loop to iterate through each column (0-7).
In the previous version, you might have simply alternated colors in a single line. In V2, you are creating a full 2D grid. The "checkerboard logic" relies on a simple mathematical truth: if you add the row index and the column index together, even sums get one color, and odd sums get the other. Breaking Down the Logic
When designing the Checkerboard V2, students must consider several key factors:
def print_board(board): for i in range(len(board)): # Joins the list elements into a single string for printing print(" ".join([str(x) for x in board[i]])) # 1. Initialize an 8x8 grid filled with 0s my_grid = [] for i in range(8): my_grid.append([0] * 8) # 2. Use nested loops to assign 1s in a checkerboard pattern for row in range(8): for col in range(8): # 3. Check if the sum of indices is odd or even if (row + col) % 2 != 0: my_grid[row][col] = 1 # 4. Print the final result print_board(my_grid) Use code with caution. Common Pitfalls