Complete the function definitions and calls. Fill each blank with the correct parameter, keyword, or return value.
def ▢1(screen, snake, food):
"""Draw the game world each tick."""
screen.fill(BG)
for i, (cx, cy) in ▢2(snake):
colour = (0,180,60) if i == 0 else GREEN
pygame.draw.rect(screen, colour,
pygame.Rect(cx*CELL_SIZE, cy*CELL_SIZE, CELL_SIZE-2, CELL_SIZE-2),
border_radius=4)
fx, fy = food
pygame.draw.circle(screen, RED,
(fx*CELL_SIZE+CELL_SIZE//2, fy*CELL_SIZE+CELL_SIZE//2), CELL_SIZE//3)
pygame.display.▢3()
def spawn_food(snake):
"""Return a random food position not overlapping snake."""
while True:
pos = (random.randint(0,GRID_COLS-1), random.randint(0,GRID_ROWS-1))
if pos ▢4 snake:
▢5 pos
# ── inside the game loop ──
draw(▢6, snake, food)
food = spawn_food(▢7)
d___e________f___n_____r_____s_____s____The function definitions below have 3 bugs. Type the corrected line for each.
def draw(snake, food): # Bug 1 – missing parameter
screen.fill(BG)
# ... drawing code ...
pygame.display.flip()
def spawn_food(snake):
while True:
pos = (random.randint(0,GRID_COLS-1), random.randint(0,GRID_ROWS-1))
if pos not in snake:
pass # Bug 2 – nothing is returned
font = pygame.font.SysFont("Arial", 20, bold=True)
def draw_score(score):
surf = font.render(f"Score: {score}", True, WHITE)
screen.blit(surf, (8, 6))
# In the game loop:
draw(snake) # Bug 3 – missing argument
Bug 1
Buggy line:
Your fix:
Hint: The function draws onto `screen` but never receives it — add it as the first parameter.
Bug 2
Buggy line:
Your fix:
Hint: The function finds a valid position but never hands it back. What keyword sends a value out of a function?
Bug 3
Buggy line:
Your fix:
Hint: The call must pass every argument the function signature requires — check how many parameters draw() has.
Write a `draw_score(screen, score)` function that renders the score in the top-left corner using `pygame.font.SysFont`. Make sure `screen` is a parameter, not a global.
font = pygame.font.SysFont("Arial", 20, bold=True)
def draw_score(screen, score):
# YOUR CODE: render f"Score: {score}" in WHITE
# blit it at position (8, 6)
pass
# Call it inside your draw() function:
# draw_score(screen, score)
**Challenge:** Refactor the entire drawing pipeline so `draw()` calls `draw_score()` internally. Then write a second function `draw_grid(screen)` that overlays a faint grid on the background. Paste both functions and explain how you chose their parameters.
Answer all 5 questions, then the Reflective Journal will unlock.
1. Why is str(score) needed in: 'Score: ' + str(score)?
2. What does score += 1 mean?
3. if score % 5 == 0: level += 1 — this triggers when:
4. To restart the game when R is pressed, which code is correct?
5. Increasing level speed means:
Answer each prompt thoughtfully. There are no right or wrong answers — this is your own reflection.