: Using board[row][col] = 1 satisfies the CodeHS requirement that you must actually modify the list elements.
def create_board(): board = [] for i in range(8): row = [] for j in range(8): # Check if the sum of indices is even or odd if (i + j) % 2 == 0: row.append(0) else: row.append(1) board.append(row) return board # Usage my_board = create_board() print_board(my_board) Use code with caution. Copied to clipboard π‘ Key Logic: The Modulo Operator
: The middle rows (indices 3 and 4) are skipped by the if statement, ensuring they remain empty as requested. Common Pitfall
The condition if row < 3 or row > 4 targets the "top 3" (0, 1, 2) and "bottom 3" (5, 6, 7) rows as required by the exercise.
This creates the alternating pattern automatically.
: Using board[row][col] = 1 satisfies the CodeHS requirement that you must actually modify the list elements.
def create_board(): board = [] for i in range(8): row = [] for j in range(8): # Check if the sum of indices is even or odd if (i + j) % 2 == 0: row.append(0) else: row.append(1) board.append(row) return board # Usage my_board = create_board() print_board(my_board) Use code with caution. Copied to clipboard π‘ Key Logic: The Modulo Operator
: The middle rows (indices 3 and 4) are skipped by the if statement, ensuring they remain empty as requested. Common Pitfall
The condition if row < 3 or row > 4 targets the "top 3" (0, 1, 2) and "bottom 3" (5, 6, 7) rows as required by the exercise.
This creates the alternating pattern automatically.
Report job:
Access 160,000+ vetted remote jobs and get daily alerts.