UESL Game Maker · Mission 2 of 2

Build a collection of levels

Grow Star Trail without writing a new variable and calculation for every level.

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: Represent UESL level data with a list and use it to manage complexity.

Success criteria: Access the intended element, update/append correctly, and explain why the same total calculation works for different lengths.

Tech Talk · Start with a collection

Data abstraction lets a name and operations stand for a collection, without requiring code to manage its storage details. In 3.1, each level had a separate variable. Here, level_stars = [10, 20, 15] represents all levels’ star counts.

A list is ordered, with an element at each index. Python’s first index is 0; College Board pseudocode starts at 1.

A. Popcorn warm-up · Find the level

Predict: What will the three output lines show: the first level’s stars, the second level’s stars, and the number of levels?

Run → change: Run Python, then switch to Pseudocode and compare. Change only the first value from 10 to 14 in either version. Which output changes, and why does the length stay the same?

Runner controls · languages, saving and reset

Each runner offers Python and Pseudocode with equivalent output and a comment explaining every pseudocode line. Switching keeps your edits in each language; it does not translate them. Save keeps the selected code/language after reload; Trash restores the Python starter. College Board's DISPLAY adds a space; OCS shows each call on a new line.

Code Runner Challenge

UESL 3.2 Warm-up - Find the level

Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...
Warm-up debrief · reveal after predicting

Both versions display 10, 20, then 3. Changing the first value to 14 changes only the first output. Replacing a value does not add a level. Python index 1 and AP index 2 both select the second level.

Explain to a partner: Point to one element, its index, and the list’s length. This warm-up is practice; the checkpoint below is the graded Popcorn task.

Reference Guide

Index map · Star Trail’s sample levels

Level label Forest Cavern Summit
Stars 10 20 15
Python index 0 1 2
AP index 1 2 3

For length n, nonnegative Python indices are 0 through n−1; AP indices are 1 through n. Empty lists have no readable element. An invalid AP index terminates the program; Python raises IndexError for an out-of-range index (AP list rules).

Read, replace and grow

Operation Python College Board pseudocode
Create a collection level_stars = [10, 20, 15] level_stars ← [10, 20, 15]
Empty project level_stars = [] level_stars ← []
Read the second level level_stars[1] level_stars[2]
Replace its count level_stars[1] = 25 level_stars[2] ← 25
Count levels len(level_stars) LENGTH(level_stars)
Add at the end level_stars.append(12) APPEND(level_stars, 12)
Insert at position two level_stars.insert(1, 8) INSERT(level_stars, 2, 8)
Remove position two level_stars.pop(1) REMOVE(level_stars, 2)

B. Popcorn checkpoint · Extend the level sequence

Predict: Write the new collection and level count before running. Which AP index selects the same second level as Python index 1?

Run → change: Check both languages. Change the appended value from 5 to 8 in one version and rerun. Explain why updating an element keeps the length, while appending increases it. Record the original prediction, code, output and AP index in your homework’s Popcorn section.

Code Runner Challenge

UESL 3.2 Popcorn - Extend the level sequence

Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...
Checkpoint debrief · reveal after predicting

Both versions display [6, 12, 12, 5], then 4. AP index 2 and Python index 1 select the second level.

Changed version: Appending 8 instead gives [6, 12, 12, 8], still four levels. Inserting adds an element at a chosen position and shifts later elements; removing closes the gap and decreases the length by one.

Other representations and copying

Values may repeat and types may mix, such as ["Forest", 10]; our counter keeps every element numeric so addition makes sense. Lists are also called arrays in some languages.

A string is an ordered character sequence: Python "Forest"[0] is "F". Strings cannot be edited character by character; lists can be changed. Copying: Python other = level_stars shares the same list; level_stars.copy() makes a separate shallow copy, sufficient for these numbers. AP other ← level_stars copies the list (Python lists, AP assignment).

Quick partner check: If Python uses other = level_stars, would changing other[0] also affect level_stars? Explain before opening the answer.

Copying debrief

Yes: both names refer to the same Python list. Use other = level_stars.copy() for a separate copy of these numbers. AP other ← level_stars copies the list.

Code Examples

C. Apply the abstraction · Total the whole game

The supplied loop visits each level’s star count. Predict: How many levels and total stars will it display? Run → change: Try [10, 20, 15, 12], then [], changing only the list. Explain why the loop needs no new line for a fourth level.

Code Runner Challenge

UESL 3.2 - Total the level collection

View IPYNB Source
# CODE_RUNNER: UESL 3.2 - Total the level collection
level_stars = [10, 20, 15]
total_stars = 0
for stars in level_stars:
    total_stars = total_stars + stars
print(len(level_stars))
print(total_stars)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Both versions output: 3, then 45. Read these as level count → total stars. With [10, 20, 15, 12], expect 4, 57; with [], expect 0, 0.

Maker checkpoint: Adding a level changes the collection. The traversal stays the same. A three-element hardcoded sum would still need editing. Reset total_stars before every calculation.

From College Board: Topic 3.2 connects list/string representations with explaining how abstraction reduces program complexity (AAP-1.C/D, pp. 65–66). Merely storing a list is insufficient evidence: explain which repeated edits it eliminates.

Hacks & Practice Tasks

MCQ Check · Maker decisions

Record A, B or C for each before revealing the key.

  1. Which AP index selects the first level? A 0 · B 1 · C the list length.
  2. Replacing one count changes the list length by: A 0 · B 1 · C −1.
  3. What does APPEND(level_stars, 5) do? A Change level five · B Add five levels · C Add one element with value 5.
  4. Why use a list plus traversal for 100 levels? A It always runs faster · B It avoids a separate variable and sum edit for every level · C It prevents all errors.
MCQ answers and explanations

B, A, C, B. AP starts at 1; replacement keeps the length; APPEND adds one item; the benefit here is simpler maintenance, not a guaranteed speed increase. Record your actual score out of 4.

Homework Hack · Grow your UESL game

  1. Refactor the 3.1 prototype into level_stars = [12, 18, 10]. Explain that each element is one level’s collected stars, in level order.
  2. Add 5 to the second level and append 7 for a new level. Use Example C’s traversal to print the collection, level count and total. Expect [12, 23, 10, 7], 4, 52.
  3. Test the total-only code with []: expect 0, 0. Skip the second-level update when there is no second element.
  4. Explain the edits a list avoids compared with 100 separate variables. Add a design-thinking note: player/maker need, goal, representation considered, prototype and one actual test/revision. Suggest clear level labels so players need not understand indices.

Connection to 3.1: Changing a list still does not recalculate a previously stored total. The list organizes state; assignment and the traversal update it.

All Python lessons