Python 3.01 - Variables and Assignments HW
Python 3.01 Variables and Assignments
Completed the Popcorn checkpoint, the MCQ, the Comet Climb star-counter homework, both tests, and the design-thinking note.
Popcorn
Prediction: 12, then 8. checkpoint_stars copies the value 8 when it is assigned, so changing stars afterward doesn’t change it.
Code Runner Challenge
UESL 3.1 Popcorn - Keep the checkpoint
View IPYNB Source
# CODE_RUNNER: UESL 3.1 Popcorn - Keep the checkpoint
stars = 8
checkpoint_stars = stars
stars = stars + 4
print(stars)
print(checkpoint_stars)
MCQ
Answers: B, A, C, B
Score: 4/4
- B — string:
"007"keeps its leading zeros. - A — 8: the checkpoint copied 8 before
starschanged. - C —
←: the AP assignment operator. - B: a stored total only changes when it is reassigned.
Homework
A string game name, a Boolean reduced-motion setting, and three integer level-star variables (12, 18, 10).
Prediction: original 40, stored 40 after the bonus, recalculated 45.
Code Runner Challenge
UESL 3.1 Homework - star counter
View IPYNB Source
# CODE_RUNNER: UESL 3.1 Homework - star counter
game_title = "Comet Climb"
reduced_motion = True
level_one_stars = 12
level_two_stars = 18
level_three_stars = 10
total_stars = level_one_stars + level_two_stars + level_three_stars
print(game_title)
print(reduced_motion)
print(total_stars)
# The bonus changes level two, but total_stars does not update by itself.
level_two_stars = level_two_stars + 5
print(total_stars)
# Reassign total_stars to recalculate it.
total_stars = level_one_stars + level_two_stars + level_three_stars
print(total_stars)
Tests
Each test starts from fresh values. Bonus 5: 40, 40, 45. Bonus 0: 40, 40, 40.
Code Runner Challenge
UESL 3.1 Tests - bonus 5 and bonus 0
View IPYNB Source
# CODE_RUNNER: UESL 3.1 Tests - bonus 5 and bonus 0
for bonus in [5, 0]:
level_one_stars = 12
level_two_stars = 18
level_three_stars = 10
total_stars = level_one_stars + level_two_stars + level_three_stars
print("Bonus", bonus, "original:", total_stars)
level_two_stars = level_two_stars + bonus
print("Bonus", bonus, "stored:", total_stars)
total_stars = level_one_stars + level_two_stars + level_three_stars
print("Bonus", bonus, "recalculated:", total_stars)
Design Thinking
Player need: players want to see the star total change after a bonus, and some players need less motion on screen.
Goal: keep the game state in clearly named variables that are easy to trace.
Representation considered: a string like "on"/"off" for reduced motion, but a Boolean fits better since it only has two states.
Prototype: the Comet Climb counter with a title, reduced-motion setting, three level variables and a total.
Test/revision: the bonus-5 test still showed 40, so I added a line that reassigns total_stars, which then showed 45.
Why reduced motion is a player choice: motion that’s fine for one player can make another dizzy, so each player should decide.