What or failed test case is the autograder showing?
You must use nested loops and assignment statements to modify an existing grid of zeros. 💻 Implementation (Python)
Once you understand the toggle-and-reset pattern, you can adapt this code to draw any tile-based pattern (chessboards, game boards, pixel art, etc.). 9.1.7 Checkerboard V2 Codehs
# Get the dimensions from the user (or specific constants if the problem asks) width = int(input("What width? ")) height = int(input("What height? "))
is a common way to format the output so it looks like a clean grid in the console. Example Code Snippet The following logic illustrates how to construct the grid correctly: # 1. Initialize the board # 2. Outer loop for rows # 3. Inner loop for columns # 4. Check for even/odd sum : row.append( : row.append( ) board.append(row) # 5. Print the formatted board board: print .join([str(x) Use code with caution. Copied to clipboard Why version 2 is different What or failed test case is the autograder showing
The program correctly generates a checkerboard pattern by iterating through a 2D grid and setting the color of each cell based on the parity of the sum of its row and column indices.
Top Row (Row 0): (0,0) sum=0 [Even], (0,1) sum=1 [Odd], (0,2) sum=2 [Even] # Get the dimensions from the user (or
But wait — V2 often wants you to , not row+col.
Do not use hardcoded numbers like 8 in your loops unless explicitly told to do so. Always use .length so your code works dynamically regardless of the grid size CodeHS tests against. Conclusion
The goal is to create a grid where the colors of the squares alternate like a traditional checkerboard. Unlike the first version of this exercise, "V2" usually requires a more dynamic approach—often utilizing variables for row and column counts or specific helper methods to determine which color should be placed at a specific coordinate. The Logic Behind the Grid