Popcorn

Language: Python

Prediction: stars will be 12, but checkpoint_stars will stay 8.

Code Runner Challenge

UESL 3.1 Popcorn - Keep the checkpoint

View IPYNB Source
# CODE_RUNNER: UESL 3.1 Popcorn - Keep the checkpoint
stars = 8 # Set the initial value of the stars variable to 8
checkpoint_stars = stars # Copy the CURRENT value of stars (8) into checkpoint_stars
stars = stars + 4 # Evaluate the right side first (8 + 4 = 12), then assign 12 back to stars

print(stars) # Live stars: 12
print(checkpoint_stars) # Checkpoint stars: still 8
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Actual output: 12, then 8.

Explanation: checkpoint_stars = stars copies the value stars held at that moment (8). It does not link the two variables. When stars = stars + 4 runs, Python evaluates the right side first (8 + 4 = 12) and assigns 12 to stars only, so the checkpoint keeps the earlier value of 8.

MCQ

MCQ 3.1: 4/4 answers: B,A,C,B
  1. B (string): "007" is text, and an integer would drop the leading zeros.
  2. A (8): checkpoint got a copy of 8 before stars was reassigned.
  3. C (←): in AP pseudocode, ← assigns and = tests equality.
  4. B: a stored total only changes when it is reassigned or recalculated.

Homework

Language: Python

My game is Little Red Riding Hood: players collect apples (my version of stars) across three levels: the forest, the river, and the village.

Prediction (Test 1, bonus = 5): name Little Red Riding Hood, setting True, original total 40, stored total after the bonus still 40, recalculated total 45.

Code Runner Challenge

UESL 3.1 Homework - Test 1 (bonus of 5)

View IPYNB Source
# CODE_RUNNER: UESL 3.1 Homework - Test 1 (bonus of 5)
game_title = "Little Red Riding Hood" # str: the game's name is text
reduced_motion = True # bool: the player's reduced-motion setting is a true/false choice
forest_apples = 12 # int: apples collected in level one (forest)
river_apples = 18 # int: apples collected in level two (river)
village_apples = 10 # int: apples collected in level three (village)
bonus = 5 # int: bonus awarded to level two

total_apples = forest_apples + river_apples + village_apples # Store the total: 12 + 18 + 10 = 40
print(game_title) # Little Red Riding Hood
print(reduced_motion) # True
print(total_apples) # Original total: 40

river_apples = river_apples + bonus # Award the bonus to level two: 18 + 5 = 23
print(total_apples) # Stored total is still 40 - it is a saved value, not a live formula

total_apples = forest_apples + river_apples + village_apples # Recalculate: 12 + 23 + 10 = 45
print(total_apples) # Updated total: 45
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Actual output: Little Red Riding Hood, True, 40, 40, 45. This matches my prediction.

Tests

Test 1 (bonus = 5): see the Homework cell above.

  • Prediction: original/stored total 40, updated total 45.
  • Actual output: 40, 40, 45.
  • Explanation: after river_apples went from 18 to 23, total_apples still printed 40. It was assigned once from the values at that moment, so it doesn’t update itself when a level changes. It only became 45 after I reassigned it with the addition again.

Test 2 (restart with bonus = 0): every variable is re-initialized with fresh starting values (12, 18, 10).

  • Prediction: all three totals will be 40.

Code Runner Challenge

UESL 3.1 Homework - Test 2 (restart with bonus of 0)

View IPYNB Source
# CODE_RUNNER: UESL 3.1 Homework - Test 2 (restart with bonus of 0)
game_title = "Little Red Riding Hood" # Re-initialize every variable with fresh starting values
reduced_motion = True
forest_apples = 12
river_apples = 18
village_apples = 10
bonus = 0 # This time the bonus is 0

total_apples = forest_apples + river_apples + village_apples # 12 + 18 + 10 = 40
print(game_title) # Little Red Riding Hood
print(reduced_motion) # True
print(total_apples) # Original total: 40

river_apples = river_apples + bonus # 18 + 0 = 18, so nothing changes
print(total_apples) # Stored total: 40

total_apples = forest_apples + river_apples + village_apples # Recalculate: 12 + 18 + 10 = 40
print(total_apples) # Updated total: 40
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...
  • Actual output: Little Red Riding Hood, True, 40, 40, 40.
  • Explanation: with a bonus of 0, river_apples stays 18, so the original, stored, and recalculated totals are all 40. This confirms the recalculation only changes the total when a level’s value actually changes.

Design Thinking

  • Player need: some players get dizzy or uncomfortable from fast motion and screen shake, and every player wants to see their apple count update correctly after earning a bonus.
  • Goal: model the game’s state with clear names and the right types, and make sure the total is always recalculated after a bonus.
  • Representation considered: I considered storing reduced motion as a string like "on"/"off". I chose a Boolean (True/False) because it is a yes/no choice and can’t be misspelled. I used int for apple counts because they are whole items, and str for the game name.
  • Prototype: separate level variables (forest_apples, river_apples, village_apples), a bonus variable, and a total_apples that is recalculated after the bonus.
  • Test / revision: my first version printed a stale total of 40 after the bonus. I revised it to reassign total_apples right after the bonus, then retested with bonus 5 (40 → 45) and bonus 0 (40 → 40). I also replaced “subtract the bonus” with a fresh restart so each test starts from its own initial values.
  • Why reduced motion should be a player choice: motion sensitivity differs from person to person. Some players need calmer visuals, while others enjoy the animations. Making it a setting lets each player pick what works for them without changing the gameplay or its difficulty.
  • Assignment vs. comparison: in Python, = assigns (stars = 10 stores 10) and == compares (stars == 10 checks whether it is 10). In AP pseudocode, ← assigns and = compares.
  • Looking ahead to 3.2: 100 separate level variables would mean 100 names to type, 100 terms in the total, and a total that breaks whenever one is forgotten. A list fixes this by storing all the levels together and letting a loop add them up.