Maya nodded. "Ah, the classic v2 trap. Did you look at the 'answers' in the documentation?"
The easiest way to determine the color of any cell is to add its row index and column index together: If (row + col) is , apply Color A. If (row + col) is odd , apply Color B. Standard Code Implementations
Ensure your loops start at 0 and use the strictly less than operator ( < NUM_ROWS ), not less than or equal to ( <= ). 9.1.7 checkerboard v2 answers
: Add r + c and apply the modulo operators.
Instead of using 0 and 1 , use strings like "⬜" and "⬛" to create a visual board with actual block characters. Maya nodded
A 2D list is essentially a list of lists. You can think of it as a grid or a matrix:
Leo looked up. It was Maya, the TA. She was holding a mug of tea and looking amused. She pulled up a chair next to him. If (row + col) is odd , apply Color B
. In a checkerboard, a cell changes color every time you move one step in any direction. Mathematically, this happens when the sum of the row and column indices switches between even and odd. , the sum is even. , the sum is odd. By setting elements to
A checkerboard pattern relies on alternating starting values. You use the modulo operator ( i % 2 == 0 ) to check if the current row index is even or odd. : Start with 0 (e.g., 0, 1, 0, 1... ). Odd rows : Start with 1 (e.g., 1, 0, 1, 0... ). 3. Use list multiplication for efficiency