9.1.6 Checkerboard V1 Codehs [new]

9.1.6 Checkerboard v1

Here's the code for the exercise on CodeHS:

Variable Confusion:

Swapping row and col inside the setPosition function is the most common reason for a "sideways" or broken grid. Remember: X is Columns, Y is Rows. 9.1.6 checkerboard v1 codehs

Edge cases and implementation details

  1. Using a while loop to handle rows.
  2. Using a while loop inside to handle columns.
  3. Alternating the starting position (with beeper or without) each row.
  4. Placing beepers on every other cell in a row.
  5. Using helper functions for better readability.

2. Set Up the Grid

for i in range(8): # Only modify the top 3 and bottom 3 rows if i < 3 or i > 4: for j in range(8): # If the sum of indices is even, set to 1 if (i + j) % 2 == 0: board[i][j] = 1 Use code with caution. Copied to clipboard 3. Print the Result Using a while loop to handle rows

Initialize the Grid

: Create a 2D list (an 8x8 grid) filled entirely with 0s. 9.1.6 checkerboard v1 codehs

Product added to wishlist