🎯Calibrate
1Fill-in
2Debug
3Extend
4Create
🧠Concept
📓Reflect
👤 Your Details REQUIRED — fill in before you begin (★ = required)
🎯 Before You Begin Calibration Check 2 questions + 1 reflection — unlocks Tier 1
Think about what the def keyword does. When you write def my_func():, does the code inside run immediately — or does it wait until the function is called?
1 10 5
Tier 1 Fill in the Blanks Complete the function skeleton — 6 blanks

Fill in each blank so the function is correctly defined and called. Read the comments carefully for hints.

# Define a function to draw the snake on screen
def ___1___(surface, snake):        # ___1___: function name (draws the snake)
    for i, (col, row) in ___2___(snake):  # ___2___: built-in giving (index, item) pairs
        colour = DKGREEN if i == ___3___ else GREEN  # ___3___: index of head segment
        rect = (col * CELL_SIZE, row * CELL_SIZE,
                CELL_SIZE - 1, CELL_SIZE - 1)
        pygame.draw.rect(___4___, colour, rect)  # ___4___: first parameter name

# Call the function in the main loop:
___5___(screen, snake)         # ___5___: same as ___1___ — how do you run a function?

# A function with a return value (membership test):
def is_alive(head, body):
    return not (head ___6___ body[1:])  # ___6___: Python keyword — "is element in list?"
1.Function name (d________)
2.Built-in for index+value (e_________)
3.Head index (one digit)
4.First parameter name (s_______)
5.Call the function (d________)
6.Membership keyword (i_)
Tier 2 Find & Fix the Bugs 3 function bugs to correct — type the fixed line

Each code snippet below has one bug in the function definition or its body. Type the corrected line in the box.

Bug 1 — Wrong parameter list

def draw_food(food_x, food_y): # missing a parameter!
Called as: draw_food(screen, food_x, food_y) — 3 arguments passed, but only 2 parameters defined.
💡 Hint: The function draws onto a surface — add the missing first parameter.

Bug 2 — print instead of return

def check_wall(hx, hy): print(hx < 0 or hx >= GRID_COLS or hy < 0 or hy >= GRID_ROWS)
The caller does: if check_wall(snake[0][0], snake[0][1]): running = False — but check_wall always returns None!
💡 Hint: To give a value back to the caller, use return, not print.

Bug 3 — Missing colon

def show_score(surface, score) # SyntaxError!
💡 Hint: Every def line must end with a : to open the function body.
💬 Reflection After Tier 2 — What did you find hardest?
Tier 3 Extend the Code Add a draw_score function to render the score

The starter code below already draws the snake and food. Your task: write a draw_score(surface, score, font) function that renders the score as text at position (8, 8) on screen.

# --- STARTER (already working) ---
def draw_snake(surface, snake):
    for i, (col, row) in enumerate(snake):
        colour = DKGREEN if i == 0 else GREEN
        rect = (col*CELL_SIZE, row*CELL_SIZE, CELL_SIZE-1, CELL_SIZE-1)
        pygame.draw.rect(surface, colour, rect)

def draw_food(surface, food_x, food_y):
    rect = (food_x*CELL_SIZE, food_y*CELL_SIZE, CELL_SIZE-1, CELL_SIZE-1)
    pygame.draw.rect(surface, RED, rect)

# --- YOUR TASK: write draw_score here ---
# Requirements:
#   def draw_score(surface, score, font):
#   * Render the text:  font.render(f"Score: {score}", True, WHITE)
#   * Draw it at top-left: surface.blit(text, (8, 8))

# --- Main loop calls all three ---
screen.fill(BG)
draw_snake(screen, snake)
draw_food(screen, food_x, food_y)
draw_score(screen, score, font)   # <-- calls YOUR function
pygame.display.flip()
Tier 4 Create From Scratch Write game_over_screen(surface, score, font) from scratch

Write a complete game_over_screen(surface, score, font) function. It should:

  • Clear the screen: surface.fill(BG)
  • Render "GAME OVER" centered on screen using a large font size (36)
  • Render the final score below it
  • Update the display: pygame.display.flip()
  • Wait 2 seconds: pygame.time.wait(2000)

Useful trick: msg.get_rect(center=(WINDOW_W//2, WINDOW_H//2)) centres a rendered text surface.

🧠 Concept Check Functions — 5 Questions Score ≥ 80% to unlock the journal

Answer all 5 questions. You need 4 or more correct to continue.

Q1: def draw_snake(body): — what is body in this line?

Q2: What does a Python function return when it has no return statement?

Q3: Why define draw_snake(body) instead of pasting the drawing code everywhere in the main loop?

Q4: What is variable scope?

Q5: def is_collision(head, body): return head in body — what type does this function return?

📊 Post-Activity How did it go?
1 10 5
📓 Reflective Journal Functions — 5 Prompts Write at least 5 words per prompt