9.1.6 Checkerboard V1 Codehs !free! May 2026

CodeHS Exercise 9.1.6: Checkerboard, v1 , the primary goal is to create a 2D list (a "grid") representing a checkers board using 1s for pieces and 0s for empty squares. Exercise Objectives Grid Initialization

: Create an 8x8 grid (list of lists) representing a game board. Specific Pattern top 3 rows bottom 3 rows should contain 1s. middle 2 rows should contain only 0s. Output Requirement : Use a provided print_board function to display the grid in a human-readable format. Key Logical Steps Initialize the Board : Create an empty list, typically named Fill the Top Rows

: Use a loop to append three rows, each containing eight 1s. Fill the Middle Rows : Append two rows of eight 0s. Fill the Bottom Rows : Append another three rows of eight 1s. Function Call : Pass the completed list to the print_board Common Implementation Strategies Simple Append board.append([1] * 8)

within loops is the most straightforward method for version 1. Nested Loops

: Some variations or autograders may require initializing the board with 0s first and then using nested loops to selectively assign to specific indices (e.g., board[i][j] = 1 Autograder Requirements : To pass all tests on , ensure you are using assignment statements

if the prompt specifically requests them, as simply printing the pattern without storing it in a grid may cause errors. Typical Pitfalls Incorrect Function Placement : Defining the print_board function inside another block or incorrectly indenting it. Missing Middle Rows

: Forgetting that the middle two rows (index 3 and 4 in an 8-row grid) must remain empty (0s). Bypassing Assignment

: Attempting to print the pattern directly instead of modifying the elements within a list structure. specific Python code 9.1.6 checkerboard v1 codehs

for these requirements, or are you looking for the logic behind Checkerboard v2

CodeHS Exercise 9.1.6 (Checkerboard, v1) requires creating an 8x8 grid, utilizing nested loops to populate top and bottom rows with 1s in alternating positions while leaving middle rows as 0s. The solution initializes a 2D list and applies an assignment statement to update specific cells where the sum of the row and column indices is odd. For detailed code solutions, review the answers at

Summary

Create the 8x8 checkerboard

for i in range(8): row = [] for j in range(8): if (i + j) % 2 == 0: row.append("R") # R for red else: row.append("B") # B for black board.append(row)

2. Wrong Starting Color

Problem: The top-left square is black instead of gray.
Fix: Ensure your parity logic starts with (row + col) % 2 == 0 as gray. If it's reversed, swap the colors in the if statement.

Example (JavaScript-like pseudocode for CodeHS canvas)

var size = 8;
var S = 40; // pixel square size
for (var r = 0; r < size; r++) 
  for (var c = 0; c < size; c++) 
    var x = c * S;
    var y = r * S;
    if ((r + c) % 2 === 0) 
      fillRect(x, y, S, S); // filled square
     else 
      // leave background or draw empty square

If you want, tell me which language or CodeHS API (console vs. graphics) you're using and I can produce a ready-to-run solution.

(Invoking related search terms)

The "9.1.6 Checkerboard v1" exercise in CodeHS is a classic challenge designed to test your mastery of nested loops and 2D arrays (or grids). Creating a checkerboard pattern requires a logical approach to alternating colors based on row and column indices. CodeHS Exercise 9

Here is a comprehensive breakdown of the logic, the code, and how to understand the underlying math. The Logic: Why a Checkerboard? In a standard

grid, a checkerboard pattern alternates colors. If you look at the coordinates of any square: Square (0,0) is Color A. Square (0,1) is Color B. Square (1,0) is Color B. Square (1,1) is Color A.

The mathematical secret to this pattern is the sum of the indices. If you add the row index and the column index Even sums result in one color. Odd sums result in the other color. The Code Implementation

Most CodeHS versions of this exercise use the Grid class or a simple graphics library. Below is the standard structural approach using nested for loops. javascript

function start() // Define the size of the board var NUM_ROWS = 8; var NUM_COLS = 8; // Outer loop handles the rows for (var row = 0; row < NUM_ROWS; row++) // Inner loop handles the columns for (var col = 0; col < NUM_COLS; col++) // Check if the sum of row and col is even if ((row + col) % 2 == 0) drawSquare(row, col, Color.red); else drawSquare(row, col, Color.black); function drawSquare(row, col, color) var sideLength = getWidth() / 8; var x = col * sideLength; var y = row * sideLength; var rect = new Rectangle(sideLength, sideLength); rect.setPosition(x, y); rect.setColor(color); add(rect); Use code with caution. Key Components Explained 1. Nested Loops

The outer loop (row) tells the program to start at the top and move down. For every single row, the inner loop (col) runs across from left to right. This ensures every single coordinate on the grid is visited. 2. The Modulo Operator (%) The line (row + col) % 2 == 0 is the "brain" of the code. % 2 finds the remainder when divided by 2. If the remainder is 0, the number is even.

This creates the perfect alternating "staircase" effect needed for the checkerboard. 3. Coordinate Scaling Exercise name: Checkerboard v1 (often labeled "9

In CodeHS, simply saying "Row 1" doesn't tell the computer where to draw on the screen. You must multiply the row or col by the sideLength of the square to get the actual pixel position Common Pitfalls

Off-by-one errors: Ensure your loops run from 0 to NUM_ROWS - 1. Using <= instead of < will often result in the board drawing off the screen.

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.

By mastering this exercise, you aren't just drawing a grid; you are learning how data is structured in almost every modern software application—from Excel spreadsheets to the pixels on your monitor.

Are you having trouble with a specific error message in your CodeHS console, or does the logic of the modulo operator make sense now?

The Complete Code Solution

Here is the Java code for CodeHS 9.1.6 Checkerboard v1:

import acm.graphics.*;
import acm.program.*;
import java.awt.*;

public class CheckerboardV1 extends GraphicsProgram

// Define constants for better readability
private static final int ROWS = 8;
private static final int COLUMNS = 8;
private static final int SQUARE_SIZE = 50;
private static final int WINDOW_WIDTH = COLUMNS * SQUARE_SIZE; // 400
private static final int WINDOW_HEIGHT = ROWS * SQUARE_SIZE;   // 400
public void run() 
    // Set the canvas size
    setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
// Loop through each row
    for (int row = 0; row < ROWS; row++) 
        // Loop through each column in the current row
        for (int col = 0; col < COLUMNS; col++)
// Calculate the top-left corner of the square
            int x = col * SQUARE_SIZE;
            int y = row * SQUARE_SIZE;
// Create the square (rectangle)
            GRect square = new GRect(x, y, SQUARE_SIZE, SQUARE_SIZE);
// Determine the color based on parity
            if ((row + col) % 2 == 0) 
                square.setFillColor(Color.GRAY);
             else 
                square.setFillColor(Color.BLACK);
// Make sure the square is filled with the color
            square.setFilled(true);
// Add the square to the canvas
            add(square);

Typical requirements / constraints

Investigation: "9.1.6 checkerboard v1 codehs"

Step-by-Step Guide