_top_ - 9.1.6 Checkerboard V1 Codehs
def print_board(board): for row in board: print(" ".join(str(cell) for cell in row))
grid, a checkerboard pattern alternates colors. If you look at the coordinates of any square: Square (0,0) is Color A. Square (0,1) is Color B. Square (1,0) is Color B. Square (1,1) is Color A.
The board is represented with 1's and 0's:
# Initialize the board board = []
: Ensure your xPos multiplies by the column variable ( c ) and yPos multiplies by the row variable ( r ). Reversing them will cause your grid to render improperly or throw off-screen coordinates.
If you add the current row index ( r ) and column index ( c ), the sum alternates between even and odd numbers across the entire grid: Row 0, Col 0 Row 0, Col 1 Row 1, Col 0 Row 1, Col 1
The squares are outlined but not colored. Fix: You must call both setFillColor() and setFilled(true) . 9.1.6 checkerboard v1 codehs
"9.1.6 Checkerboard, v1" is just the beginning. In the following exercises (v2 and v3), you'll build on this foundation to create a more realistic checkerboard pattern. These later versions will require an alternating pattern of 1's and 0's, which is a bit more challenging. You might find yourself using the to achieve that classic checkerboard look.
The "9.1.6 Checkerboard v1" exercise in CodeHS is a classic challenge designed to test your mastery of and 2D arrays (or grids). Creating a checkerboard pattern requires a logical approach to alternating colors based on row and column indices.
Are you required to use specified by your teacher's instructions? def print_board(board): for row in board: print(" "
The ( row ) tracks the vertical progression. It starts at row 0 and moves down to row 7.
Whether you are using the (rectangles) or a Console grid array?
By mastering this exercise, you aren't just drawing a grid; you are learning how data is structured in almost every modern software application—from Excel spreadsheets to the pixels on your monitor. Square (1,0) is Color B
Once all columns for a row are determined, row_list is appended to the board . After the loops complete, the finished 8x8 board is passed to the print_board function to display the output.
print_board(board)