Activities — Step 1
Four tasks, increasing independence. Each tier unlocks when you submit the previous one. Only Tier 4 is assessed by the Code Product Rubric.
The Step 1 program is almost complete. The ? boxes are where you type. Click each one and fill in the correct value, then click Submit Tier 1.
- Click a ? box in the code below
- Type the correct value (e.g.
20for GRID_COLS) - Fill all 7 boxes, then click Submit Tier 1
- Green = correct · Red = wrong — fix and resubmit
import pygame
pygame.init()
# Grid constants
GRID_COLS = # 20 columns
GRID_ROWS = # 15 rows
CELL_SIZE = # 30x30 pixels per cell
SNAKE_SPEED = 8
# Colour constants - RGB tuples
WHITE =
GREEN = ( 0, 200, 80)
DKGREEN = ( 0, 160, 50)
RED =
BG = ( 30, 30, 30)
# Calculate window size in pixels
WINDOW_W = * CELL_SIZE
WINDOW_H = GRID_ROWS *
screen = pygame.display.set_mode((WINDOW_W, WINDOW_H))
pygame.display.set_caption("Snake")
screen.fill(BG)
pygame.display.flip()
pygame.time.wait(3000)
pygame.quit()
The code below has 3 deliberate bugs. Each will cause a crash or wrong behaviour. For each bug: identify the variable name, explain what is wrong, and write the corrected line.
import pygame pygame.init() GRID_COLS = 20 GRID_ROWS = 15 CELL_SIZE = "30" # ⚠ Bug 1 near here SNAKE_SPEED = 8 WHITE = (255, 255, 255) GREEN = [0, 200, 80] # ⚠ Bug 2 near here DKGREEN = ( 0, 160, 50) RED = (220, 50, 50) BG = ( 30, 30, 30) WINDOW_W = GRID_COLS + CELL_SIZE # ⚠ Bug 3 near here WINDOW_H = GRID_ROWS * CELL_SIZE screen = pygame.display.set_mode((WINDOW_W, WINDOW_H)) pygame.display.set_caption("Snake") screen.fill(BG) pygame.display.flip() pygame.time.wait(3000) pygame.quit()
Bug 1
Bug 2
Bug 3
The skeleton below is ~50% complete. Write every missing line to make a working Step 1 program. No bugs here — this is a writing task.
# skeleton — gaps marked with ___ import pygame pygame.init() # Write all four grid constants: GRID_COLS = ___ GRID_ROWS = ___ CELL_SIZE = ___ SNAKE_SPEED = ___ # Write the five colour constants as RGB tuples: WHITE = ___ GREEN = ___ DKGREEN = ___ RED = ___ BG = ___ # Calculate window dimensions from the constants: WINDOW_W = ___ WINDOW_H = ___ # These lines are given: screen = pygame.display.set_mode((WINDOW_W, WINDOW_H)) pygame.display.set_caption("Snake") # Write three display lines: fill, flip, wait ___ ___ ___ pygame.quit()
Add two new colour constants to Step 1:
GOLD = (255, 200, 0) for a future bonus food item, and a BORDER_COLOUR of your own choice. Then, after all your constants are defined, use print() to display the name and Python type of each colour constant (WHITE, GREEN, DKGREEN, RED, BG, GOLD, and BORDER_COLOUR). Run your program in Thonny and paste the full code and terminal output below.
Complete Tier 4 to unlock these questions.
Answer each prompt thoughtfully. There are no right or wrong answers — this is your own reflection.