# Call the function to display the board create_checkerboard()
else if (col % 2 == 0) putBeeper();
It looks like you are working on the assignment in the CodeHS Graphics course. In this assignment, you are typically asked to write a function called create_checkerboard that draws an 8x8 grid of alternating black and white squares. 9.1.6 checkerboard v1 codehs
In CodeHS Exercise 9.1.6: Checkerboard, v1, the goal is to initialize an 8x8 grid where certain rows represent checker pieces (1s) and others represent blank squares (0s)
If the sum is , the square should be 1 .This ensures that as you move one space to the right or one space down, the value always flips, creating the alternating pattern. 4. Visualize the Grid # Call the function to display the board
board = []
Always declare loop variables using var (e.g., for (var r = 0; ...) ). Forgetting var can leak the variable into global scope, breaking the nested loop logic. for i in range(8): row = [] for
for i in range(8): row = [] for j in range(8): # Check if the sum of row and column indices is even if (i + j) % 2 == 0: row.append("red") else: row.append("black") board.append(row)
for row in range(8): # Loop for each row (0-7) new_row = [] # Create an empty list for the current row for col in range(8): # Loop for each column (0-7) # Step 3: Determine if this cell should be a 1 or a 0 if row < 3 or row > 4: new_row.append(1) # Top 3 or bottom 3 rows get a 1 else: new_row.append(0) # Middle 2 rows get a 0 # Step 4: Add the completed row to the board board.append(new_row)
return win