3.01 Variables and Assignments
Store values in variables, pick fitting data types, and update values with assignment.
- Give your game a memory
- Lesson Plan
- Reference Guide
- Code Examples
- Hacks & Practice Tasks
UESL Game Maker · Mission 1 of 2
Give your game a memory
Store a player profile, preserve a checkpoint, and update a star counter.
Classroom prototype: UESL Star Trail, a game in which players collect stars across levels.
UESL’s foundation supports community and opportunities through gaming for people with intellectual and developmental disabilities. Our examples model a game maker’s settings and scores; ask players what helps them enjoy a game.
Lesson Plan
Objective: Model a UESL game’s state with variables and assignments.
Success criteria: Choose a suitable type, trace reassignment, and explain why a stored total must be recalculated.
Tech Talk · 3 minutes
A variable names a current value. game_title names text; level_one_stars names a count. Python names are case-sensitive, cannot begin with a digit, and cannot be keywords. Choose names that explain their purpose.
Evaluate the right side first, then assign the result to the left. stars = stars + 5 needs an initial value. Each assignment replaces the previous value; a total is a stored result, not a live formula. Python names can later refer to another type, but keeping a consistent purpose makes code clearer.
From College Board: Topic 3.1 covers representing values, choosing meaningful names/types, and tracing the latest assignment (AAP-1.A/B, pp. 63–64). The AP assignment arrow is ←; = tests equality.
Reference Guide
| Game-maker data | Python type/example | Why this type? |
|---|---|---|
| Game name or player tag | str: "Star Trail", "007" |
Text keeps letters and leading zeros. |
| Collected stars | int: 10 |
Count whole items. |
| Preview speed multiplier | float: 0.75 |
Allow a fractional speed. |
| Reduced-motion setting | bool: True |
A true/false choice. |
| Multiple level scores | list: [10, 20, 15] |
A collection, introduced in 3.2. |
Initialization gives a name its first value; reassignment replaces it. Python needs no separate typed declaration. "10" is text, while 10 is numeric: Python input() returns text, so int("10") + 5 gives 15 (Python input() documentation).
| Operation | Python | College Board pseudocode |
|---|---|---|
| Initialize | stars = 10 |
stars ← 10 |
| Update | stars = stars + 5 |
stars ← stars + 5 |
| Compare | stars == 10 |
stars = 10 |
| Display | print(stars) |
DISPLAY(stars) |
AP uses Boolean values true/false; the OCS runner spells them TRUE/FALSE. College Board’s DISPLAY adds a space; this runner displays each call on a new line. Our paired examples print the same values in the same order without nonstandard text-plus-number expressions.
Code Examples
Playtest controls: In C and Popcorn, select Python or Pseudocode to load the matching program. Pseudocode comments explain each line. Edits stay while switching; Save keeps the current code and language after reload. The trash button restores the Python starter. Changing one version does not translate your edits into the other.
A. Simple · Set up a player profile
game_title = "UESL Star Trail"
player_tag = "007"
preview_speed = 0.75
reduced_motion = True
print(game_title)
print(player_tag)
print(preview_speed)
print(reduced_motion)
Output: UESL Star Trail, 007, 0.75, True. These are configuration values; applying them to a game would require connecting them to its controls.
B. Intermediate · Preserve a checkpoint
stars = 10
checkpoint_stars = stars
stars = stars + 5
checkpoint_stars = checkpoint_stars + 2
print(stars)
print(checkpoint_stars)
Output: 15, then 12. Both started at 10, then changed independently. A checkpoint stores the value at the moment of assignment.
C. Complex · Playtest a star bonus
Predict the original, stored and recalculated totals. Then change the bonus from 5 to 0.
UESL 3.1 - Playtest the star counter
game_title = "UESL Star Trail"
level_one_stars = 10
level_two_stars = 20
level_three_stars = 15
total_stars = level_one_stars + level_two_stars + level_three_stars
print(game_title)
print(total_stars)
level_two_stars = level_two_stars + 5
print(total_stars)
total_stars = level_one_stars + level_two_stars + level_three_stars
print(total_stars)
Code Runner Challenge
UESL 3.1 - Playtest the star counter
View IPYNB Source
# CODE_RUNNER: UESL 3.1 - Playtest the star counter
game_title = "UESL Star Trail"
level_one_stars = 10
level_two_stars = 20
level_three_stars = 15
total_stars = level_one_stars + level_two_stars + level_three_stars
print(game_title)
print(total_stars)
level_two_stars = level_two_stars + 5
print(total_stars)
total_stars = level_one_stars + level_two_stars + level_three_stars
print(total_stars)
Both versions output: UESL Star Trail, 45, 45, 50.
| Star-counter snapshot | Before bonus | After bonus, before recalculation | After recalculation |
|---|---|---|---|
| Second level | 20 | 25 | 25 |
| Stored total | 45 | 45 | 50 |
Hacks & Practice Tasks
Popcorn Hack · Checkpoint challenge
Two minutes: Predict the live stars and checkpoint stars. Run, then explain why they differ.
UESL 3.1 Popcorn - Keep the checkpoint
stars = 8
checkpoint_stars = stars
stars = stars + 4
print(stars)
print(checkpoint_stars)
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)
Checkpoint debrief · reveal after predicting
Both versions display 12, then 8. The checkpoint holds the earlier value.
MCQ Check · Maker decisions
Record A, B or C for each before revealing the key.
- A player tag is
"007". Best type? A integer · B string · C Boolean. - After
stars ← 8,checkpoint ← stars,stars ← 12, what ischeckpoint? A 8 · B 12 · C 20. - Which AP operator assigns a value? A
=· B==· C←. - A bonus changes a level’s stars. When does a previously stored total change? A Automatically · B When reassigned/recalculated · C When displayed.
MCQ answers and explanations
B, A, C, B. Text preserves 007; the checkpoint copied 8; the arrow assigns; displaying a total does not recalculate it. Count one point per correct answer and record your actual score out of 4.
Homework Hack · Build your UESL star counter
- Choose a game name and a reduced-motion Boolean setting. Use separate level-star variables starting at
12,18,10; print the name, setting and total. - Add a bonus of
5to level two. Print the stored total, then recalculate and print it again. - Record predictions and actual results: original/stored total
40, updated total45. Restart with bonus0; all three totals should be40. - Design-thinking note: Name a player’s need, your goal, a setting/representation you considered, the prototype you built, and one test or revision. Explain why reduced motion should be a player choice.
Next mission: 3.2 replaces separate level variables with a collection. What would 100 separate variables cost a game maker to maintain?