# Assuming a standard CodeHS Python graphics setup import math # --- Constants --- SQUARE_SIZE = 40 ROWS = 8 COLS = 8 COLOR_1 = Color.red COLOR_2 = Color.black def draw_checkerboard(): for row in range(ROWS): for col in range(COLS): # 1. Calculate x, y positions x = col * SQUARE_SIZE y = row * SQUARE_SIZE # 2. Determine color using (row + col) if (row + col) % 2 == 0: rect_color = COLOR_1 else: rect_color = COLOR_2 # 3. Draw the rectangle rect = Rectangle(SQUARE_SIZE, SQUARE_SIZE) rect.set_position(x, y) rect.set_color(rect_color) add(rect) draw_checkerboard() Use code with caution. Common Mistakes and How to Avoid Them
Mixing up NUM_ROWS and NUM_COLS when calculating positions will cause your board to distort if it isn't perfectly square. 9.1.7 Checkerboard V2 Codehs
To finish the whole hall, Modulo realized he just needed to alternate between the "Obsidian-Start" row and the "Pearl-Start" row for a total of 8 rows. He wrote down a rule using the ( ) and the tile number ( "If you add the row number and the tile number ( ) and the result is even , place a Pearl (1)." "If the result is odd , place an Obsidian (0).". # Assuming a standard CodeHS Python graphics setup
Create a checkerboard pattern of squares in a graphics window using nested loops. Each square is the same size; squares alternate color (e.g., black and white). The pattern should form an N-by-N grid (commonly 8×8), and the top-left square’s color should follow the specification (typically black). He wrote down a rule using the (