Python 3.01: Variables and Assignments HW
Python 3.01 Variables and Assignments
This notebook covers the current OCS Popcorn checkpoint and UESL star-counter homework, including the required tests and design-thinking explanation.
Popcorn Hack: Checkpoint Challenge
Prediction: live stars = 12; checkpoint stars = 8. The checkpoint keeps the earlier value because assigning saved_stars = stars copies the current numeric value.
Code Runner Challenge
UESL 3.1 Popcorn - Keep the checkpoint
View IPYNB Source
# CODE_RUNNER: UESL 3.1 Popcorn - Keep the checkpoint
# Start with 8 live stars and save that value at the checkpoint.
# Changing stars afterward does not change the already stored checkpoint value.
stars = 8
saved_stars = stars
stars = stars + 4
print(stars)
print(saved_stars)
MCQ
Answers: B, A, C, B
Score: 4/4
Homework Hack: Build the UESL Star Counter
The game uses a string name, a Boolean reduced-motion setting, and three separate numeric level-star variables. The starting total is 40. After a bonus of 5 is added to level two, the stored total stays 40 until it is recalculated, when it becomes 45.
Code Runner Challenge
UESL 3.1 Homework - variables, assignment, and recalculation
View IPYNB Source
# CODE_RUNNER: UESL 3.1 Homework - variables, assignment, and recalculation
# Store the game name and accessibility setting using appropriate data types.
game_title = "Star Trail"
reduce_motion = True
# Each level starts with the values required by the lesson.
stage1_stars = 12
stage2_stars = 18
stage3_stars = 10
# Calculate and store the starting total once.
star_total = stage1_stars + stage2_stars + stage3_stars
print("Game:", game_title)
print("Reduced motion:", reduce_motion)
print("Original total:", star_total)
# Add the required bonus to level two. The old total does not update automatically.
bonus = 5
stage2_stars = stage2_stars + bonus
print("Stored total after bonus:", star_total)
# Reassign star_total to recalculate it from the updated level values.
star_total = stage1_stars + stage2_stars + stage3_stars
print("Recalculated total:", star_total)
Tests
Bonus 5 prediction/result: original 40, stored 40, recalculated 45.
Bonus 0 prediction/result: original 40, stored 40, recalculated 40.
Code Runner Challenge
UESL 3.1 Tests - verify both required bonus cases
View IPYNB Source
# CODE_RUNNER: UESL 3.1 Tests - verify both required bonus cases
# Reinitialize every test so one test cannot affect the next one.
for bonus in [5, 0]:
stage1_stars = 12
stage2_stars = 18
stage3_stars = 10
star_total = stage1_stars + stage2_stars + stage3_stars
original_total = star_total
stage2_stars = stage2_stars + bonus
stored_total = star_total
star_total = stage1_stars + stage2_stars + stage3_stars
print("Bonus:", bonus, "| Original:", original_total, "| Stored:", stored_total, "| Recalculated:", star_total)
Design Thinking
Player need: Some players may be uncomfortable with fast movement or animation.
Goal: Give the player control over reduced motion while keeping game score state easy for the maker to understand.
Representation considered: A Boolean is appropriate for reduced motion because the setting has two states, on or off. Numeric variables are appropriate for star counts.
Prototype: The star counter stores three level scores, a total, and the reduced-motion setting.
Test/revision: Testing bonuses 5 and 0 showed that a stored total must be explicitly recalculated after a level value changes. Reduced motion should remain a player choice because accessibility needs differ between players.