Complete the pygame game loop. Fill each blank so the loop handles events, redraws the screen, and limits the frame rate.
running = ▢1
clock = pygame.time.▢2()
while ▢3:
for event in pygame.event.▢4():
if event.type == pygame.▢5:
running = ▢6
screen.fill(BG)
pygame.display.▢7()
clock.▢8(▢9)
pygame.quit()
T___C____r______g__Q___F____f___t___S__________The code below has 3 bugs. For each bug, type the corrected line in the box provided.
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN: # Bug 1
running = False
screen.fill(BG)
pygame.display.flip()
clock.tick(30) # Bug 2
# Bug 3 – something is missing here
pygame.quit()
Bug 1
Buggy line:
Your fix:
Hint: Which event means the user clicked the ✕ button?
Bug 2
Buggy line:
Your fix:
Hint: Hard-coded 30 FPS ignores the SNAKE_SPEED constant — use the variable.
Bug 3
Buggy line:
Your fix:
Hint: The display is never updated — which function pushes the frame to the screen?
Add a **pause feature**: pressing the P key should toggle a `paused` variable. When `paused` is True, skip the game-update step but still redraw the screen.
running = True
paused = False
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
# YOUR CODE: toggle paused when K_p is pressed
pass
if not paused:
pass # game update goes here
screen.fill(BG)
pygame.display.flip()
clock.tick(SNAKE_SPEED)
**Challenge:** Display a live FPS counter in the top-right corner of the window each frame. Use `clock.get_fps()` and `pygame.font.SysFont` to render it. Paste your complete updated loop.
Answer all 5 questions, then the Reflective Journal will unlock.
1. What does clock.tick(FPS) control inside the game loop?
2. Which pygame event type fires when the user closes the window?
3. What is the game loop responsible for each iteration?
4. How many times does while True: run (with no break)?
5. What value does pygame.event.get() return when no events have occurred?
Answer each prompt thoughtfully. There are no right or wrong answers — this is your own reflection.
⚠️ You must complete the Concept Check above before submitting your journal.