Complete the Snake and Game class skeletons by filling in the missing parts. Each blank is a single keyword, value, or name.
Each code snippet below contains exactly one bug. Type the corrected line in the input box.
Bug 1 — Missing method parameter
Bug 2 — Missing instance reference
self.Bug 3 — Missing parentheses when instantiating
Snake without () assigns the class itself, not an instance.Add a draw(self, screen) method to both the Snake and Food classes. Each method should call pygame.draw.rect(screen, colour, rect) to draw the snake segments or food position. Use comments to explain each line.
Design a complete Game class that encapsulates the full snake game loop. Include: (1) __init__ creating Snake and Food instances, (2) update() moving the snake and checking food collision, (3) draw(screen) drawing all game elements, and (4) run() containing the main game loop. Comment each method's purpose.
Test your understanding of classes, self, __init__, and encapsulation.
1. Which keyword is used to define a class in Python?
2. What does self refer to inside a class method?
3. What is the purpose of __init__ in a Python class?
4. Given snake = Snake(), how do you call its move method?
5. What best describes encapsulation in OOP?