9.1.7 Checkerboard V2 Codehs Fixed →

Class 10 Book Notes of Maths for Sindh Board

9.1.7 Checkerboard V2 Codehs Fixed →

The color should depend on whether the sum of the row and column index is even or odd ( (row + col) % 2 == 0 ). 3. Coordinate System

Before coding, it's crucial to understand the pattern you need to create. For a standard 8x8 board, the pattern of the first few rows looks like this:

No. CodeHS has multiple checkerboard exercises across different courses and units, including , 8.4.5 Checkerboard , 1.17.6 Checkerboard Karel , and 6.1.6 checkerboard .

Ensure you're actually using an if statement to check positions 1.2.4. 9.1.7 Checkerboard V2 Codehs

function start() var size = 40; // size of each square var startX = 0; var startY = 0; for(var row = 0; row < 8; row++) for(var col = 0; col < 8; col++) var x = startX + col * size; var y = startY + row * size;

// Draw the checkerboard for (var row = 0; row < rows; row++) for (var col = 0; col < cols; col++) // Alternate between light and dark colors var color = (row + col) % 2 === 0 ? 'lightgray' : 'gray'; drawSquare(col * squareSize, row * squareSize, color);

The outer loop for r in range(NUM_ROWS): starts at row 0. Before moving to row 1, it hands control to the inner loop for c in range(NUM_COLS): . The inner loop runs completely across all columns. This means the program draws the board left-to-right, top-to-bottom. 3. Coordinate Positioning The color should depend on whether the sum

System.out.println(); // new line after each row

A checkerboard is defined by a simple mathematical rule:

def start(): # 1. Initialize an 8x8 grid filled with 0s rows = 8 cols = 8 board = [] for i in range(rows): row = [] for j in range(cols): row.append(0) board.append(row) # 2. Use nested loops to fill in the 1s for row in range(rows): for col in range(cols): # The checkerboard logic: # If the sum of indices is odd, make it 1 if (row + col) % 2 == 1: board[row][col] = 1 # 3. Print the board (as required by the exercise) for row in board: print(row) # Run the function start() Use code with caution. Explanation of the Code For a standard 8x8 board, the pattern of

This exercise often follows a simpler, less restrictive version, requiring students to now not only create a checkerboard pattern but to structure their code according to specific, sometimes challenging, automated testing requirements.

: In Python, all code within the checkerboard function must be indented properly to execute as a single block.

add(rect);