Python 3.01: Variables and Assignments HW
Popcorn
Checkpoint challenge: keep the checkpoint while the live star count changes.
Code Runner Challenge
Popcorn - Keep the Checkpoint
View IPYNB Source
# CODE_RUNNER: Popcorn - Keep the Checkpoint
# Popcorn: checkpoint_stars copies the value of stars at this moment.
stars = 8
checkpoint_stars = stars
stars = stars + 4
print(stars)
print(checkpoint_stars)
Prediction: 12, then 8
Actual output:
Code Runner Challenge
Homework - UESL Star Counter (bonus = 5)
View IPYNB Source
12
8
Why they differ: checkpoint_stars = stars copies the value 8 at the moment of assignment. It does not link the two variables. When stars = stars + 4 runs, Python evaluates the right side first (8 + 4 = 12) and assigns the result only to stars, so checkpoint_stars keeps its stored value of 8.
MCQ
| MCQ 3.1: 4/4 | answers: B, A, C, B |
- B (string):
"007"is text. Storing it as an integer would drop the leading zeros and turn it into7. - A (8):
checkpoint ← starsstored the value 8. Reassigningstars ← 12afterward does not changecheckpoint. - C (←): In AP CSP pseudocode,
←assigns a value, while=tests equality. - B (when reassigned/recalculated): A stored total is a value saved at one moment, not a live formula, so it only changes when the code assigns it again.
Homework
UESL star counter: a game name, a reduced-motion setting, three separate level-star variables, and a bonus added to level two.
Code Runner Challenge
Test 2 - Bonus = 0
View IPYNB Source
# CODE_RUNNER: Homework - UESL Star Counter (bonus = 5)
# Game settings: a string for the name, a Boolean for the true/false accessibility choice.
game_title = "UESL Cosmic Collector"
reduced_motion = True
bonus = 5
# Separate level-star counts are whole numbers, so they are ints.
level_one_stars = 12
level_two_stars = 18
level_three_stars = 10
# The total is calculated once and stored. It is a snapshot, not a live formula.
total_stars = level_one_stars + level_two_stars + level_three_stars
print(game_title)
print(reduced_motion)
print(total_stars)
# The right side is evaluated first (18 + 5), then the result replaces level_two_stars.
level_two_stars = level_two_stars + bonus
# total_stars still holds the old stored value because nothing reassigned it yet.
print(total_stars)
# Recalculating reassigns total_stars using the updated level_two_stars.
total_stars = level_one_stars + level_two_stars + level_three_stars
print(total_stars)
The same logic in College Board pseudocode:
game_title ← "UESL Cosmic Collector"
reduced_motion ← true
bonus ← 5
level_one_stars ← 12
level_two_stars ← 18
level_three_stars ← 10
total_stars ← level_one_stars + level_two_stars + level_three_stars
DISPLAY(game_title)
DISPLAY(reduced_motion)
DISPLAY(total_stars)
level_two_stars ← level_two_stars + bonus
DISPLAY(total_stars)
total_stars ← level_one_stars + level_two_stars + level_three_stars
DISPLAY(total_stars)
Tests
Each test starts fresh with all variables initialized from the beginning.
Test 1: bonus = 5
Prediction: original total 40, stored total after the bonus 40, recalculated total 45
Actual output:
UESL Cosmic Collector
True
40
40
45
Explanation: The bonus changed level_two_stars from 18 to 23, but the stored total_stars stayed at 40 until it was recalculated. After recalculating, 12 + 23 + 10 = 45.
Test 2: bonus = 0
# CODE_RUNNER: Test 2 - Bonus = 0
# Game settings: a string for the name, a Boolean for the true/false accessibility choice.
game_title = "UESL Cosmic Collector"
reduced_motion = True
bonus = 0
# Separate level-star counts are whole numbers, so they are ints.
level_one_stars = 12
level_two_stars = 18
level_three_stars = 10
# The total is calculated once and stored. It is a snapshot, not a live formula.
total_stars = level_one_stars + level_two_stars + level_three_stars
print(game_title)
print(reduced_motion)
print(total_stars)
# The right side is evaluated first (18 + 5), then the result replaces level_two_stars.
level_two_stars = level_two_stars + bonus
# total_stars still holds the old stored value because nothing reassigned it yet.
print(total_stars)
# Recalculating reassigns total_stars using the updated level_two_stars.
total_stars = level_one_stars + level_two_stars + level_three_stars
print(total_stars)
Prediction: all three totals are 40
Actual output:
UESL Cosmic Collector
True
40
40
40
Explanation: Adding 0 leaves level_two_stars at 18, so the recalculated total is still 12 + 18 + 10 = 40. This confirms the second print matches the first because nothing changed, and the third print only changes when a level’s value actually changes.
Design Thinking
- Player need: Some players find fast or flashing animations uncomfortable or distracting, so they need control over how much motion the game shows.
- Goal: Let each player set their own comfort level while still tracking their stars correctly.
- Representation I considered: I chose a Boolean (
reduced_motion = True) because the setting is a true/false choice. I considered a number for “motion level,” but a simple on/off is clearer for a first prototype. - Prototype: A star counter with a game name, a reduced-motion setting, three level variables, and a bonus that requires recalculating the total.
- Test and revision: Testing with
bonus = 5showed the stored total stays at 40 until it is recalculated, so I added a comment in the code to make that clear. Testing withbonus = 0confirmed all three totals match. - Why reduced motion should be a player choice: Players have different needs, and only the player knows what feels comfortable. A setting they control respects that, while forcing reduced motion on everyone would take away a feature others enjoy.
Next mission thought: 100 separate level variables would mean 100 names to create, 100 terms in the total, and 100 places to update when anything changes. A list (3.2) stores them all under one name.