🎯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 data and behaviour belong together in a Snake object. What attributes does it need, and what operations does it perform on itself?
1 10 5
Tier 1 Fill in the Blanks Complete the code skeleton — 7 blanks

Complete the Snake class. Fill each blank with the correct attribute name, method body, or keyword.

class Snake:
    def __init__(self, start_x, start_y):
        self.▢1     = [(start_x, start_y),
                              (start_x-1, start_y),
                              (start_x-2, start_y)]
        self.body_set   = ▢2(self.body)
        self.▢3 = "RIGHT"
        self.grew       = False

    def turn(self, new_dir):
        opposite = {"UP":"DOWN","DOWN":"UP",
                    "LEFT":"RIGHT","RIGHT":"LEFT"}
        if new_dir != opposite[self.▢4]:
            self.direction = ▢5

    def is_alive(self):
        hx, hy = self.body[▢6]
        return (0 <= hx < GRID_COLS) and (0 <= hy < GRID_ROWS) \
               and self.body[0] not in set(self.body[▢7:])
1.Blank 1: b___
2.Blank 2: s__
3.Blank 3: d________
4.Blank 4: d________
5.Blank 5: n______
6.Blank 6: _
7.Blank 7: _
Tier 2 Find & Fix the Bugs 3 bugs to correct

The Snake class below has 3 bugs. Type the corrected line for each.

class Snake:
    def __init__(self, sx, sy):
        self.body      = [(sx,sy),(sx-1,sy),(sx-2,sy)]
        self.body_set  = set(self.body)
        self.direction = "RIGHT"

    def turn(self, new_dir):
        opposite = {"UP":"DOWN","DOWN":"UP","LEFT":"RIGHT","RIGHT":"LEFT"}
        if new_dir != opposite[direction]:   # Bug 1 – missing self.
            self.direction = new_dir

    def move(self):
        hx, hy = body[0]                    # Bug 2 – missing self.
        dx, dy = {"RIGHT":(1,0),"LEFT":(-1,0),
                  "UP":(0,-1),"DOWN":(0,1)}[self.direction]
        new_head = (hx+dx, hy+dy)
        self.body.append(new_head)          # Bug 3 – wrong end
        self.body_set.add(new_head)
        if not self.grew:
            tail = self.body.pop()
            self.body_set.discard(tail)
        self.grew = False

Bug 1

Buggy line:

if new_dir != opposite[direction]:

Your fix:

Hint: `direction` is an instance attribute — access it through `self.` inside a method.

Bug 2

Buggy line:

hx, hy = body[0]

Your fix:

Hint: `body` is `self.body` — the list is an attribute of the instance, not a standalone variable.

Bug 3

Buggy line:

self.body.append(new_head)

Your fix:

Hint: The new head goes at the FRONT of the body list (index 0), not appended to the back.

Reflection 2 Mid-Point Check-In
Tier 3 Extend the Code Add the feature described below

Complete the `Snake.move()` method (starter below). It should compute the new head from direction, update body and body_set, and handle growing.

def move(self):
    hx, hy = self.body[0]
    dx, dy = {"RIGHT":(1,0),"LEFT":(-1,0),
              "UP":(0,-1),"DOWN":(0,1)}[self.direction]
    new_head = (hx + dx, hy + dy)   # no wrap here; handle in caller if needed

    # YOUR CODE:
    # 1. Insert new_head at front of self.body and self.body_set
    # 2. If not self.grew: pop tail from self.body and discard from self.body_set
    # 3. Reset self.grew = False
    pass
Tier 4 Create from Scratch Open-ended challenge

**Challenge:** Write a `Game` class that owns a `Snake` instance plus `food`, `score`, and `running`. Give it `handle_events()`, `update()`, and `draw(screen)` methods. Paste the complete class.

🧠 Concept Check Test Your Understanding 5 quick questions — required before the Reflective Journal 🔒

Answer all 5 questions, then the Reflective Journal will unlock.

1. TypeError: unsupported operand type(s) for +: 'int' and 'str' usually means:

2. Why read a Python traceback from the bottom up?

3. Adding print(snake_body) inside the game loop helps because:

4. IndentationError means:

5. 'Rubber-duck debugging' means:

📓 Reflective Journal 5 prompts — required before Step 8 is marked complete 🔒

Answer each prompt thoughtfully. There are no right or wrong answers — this is your own reflection.

🎯 Post-Activity Check-In After Completing All Tiers Complete after the Reflective Journal to finish this step 🔒
1. How confident do you feel about this step’s concepts now? (1 = not confident, 10 = very confident)
1 10 5
2. Your Tier 1 first-attempt score (auto-filled)
%