S09 · Sat, Nov 21, 2026

Power Up a Device

Count repeated actions, repair an off-by-one mistake, and power the observatory device with exactly enough sparks.

S09 · 1 / 20

S09 · Power Up a Device

Nova reaches the Storm Engine on the observatory approach. Each spark is one real charging action. Power it up for the next readiness check.

S09 · 2 / 20

Two journeys, one mission

Explorer Journey: the Guardian has led us to the device. Python Journey: use integers from S02 and loops from S06. Today is step 9 / 30.

S09 · 3 / 20

Today in Python: counters

Keep an integer counter, update it in a simple loop, predict exact success, diagnose an off-by-one mistake, and write one basic assertion.

S09 · 4 / 20

Review integers

goal = 3
count = 0

Both values are integers: whole numbers. Zero means no charging actions yet. The goal is the intended number of actions.

S09 · 5 / 20

One interaction = one update

count = count + 1

Read the old value, add one, then assign the result back to count. One successful E interaction in Trail adds one spark.

S09 · 6 / 20

Predict exact success

Before running Python or Trail, predict the count after interactions 1, 2, 3, and 4. Circle the exact interaction where success should first appear for goal 3.

S09 · 7 / 20

Trace the count

Start          0
Interaction 1  1
Interaction 2  2
Interaction 3  3 ← first success
Interaction 4  4

Interaction 2 is one spark short. The third update reaches the goal.

S09 · 8 / 20

Run the canonical starter

goal = 3
count = 0

for interaction_number in range(1, goal + 1):
    count = count + 1
    print(interaction_number, count)

# TODO: add one assertion that proves count reached goal.
python lessons/sessions/s09/student/starter.py

The starter loop is correct. range stops before its second number, so this loop visits 1, 2, and 3. The assertion is your unfinished task.

S09 · 9 / 20

Create and find the off-by-one bug

First add your assertion below the TODO. Then temporarily shorten only the loop stop:

for interaction_number in range(1, goal):

Predict the final count, then run. Only 1 and 2 print; the assertion fails. Off-by-one means one update too few or too many.

S09 · 10 / 20

Repair the smallest line

for interaction_number in range(1, goal + 1):

Restore the stop value, rerun, and check all three updates. Explain why stopping before 4 includes 3.

S09 · 11 / 20

Explain one assertion

Write a check that the final count equals the goal. Try it yourself before reading the shape below.

Compare your assertion
assert count == goal

A passing assertion is silent. A false check raises AssertionError. It protects the expected final count and catches the shortened loop ending at 2. No testing framework is needed.

S09 · 12 / 20

Python → YAML → Trail

  • Local Python models repeated counting and update logic.
  • Package YAML declares the counter goal and goal-reached message.
  • Trail owns the actual interaction count during the session. Student Python does not execute inside Trail.

S09 · 13 / 20

Read the authored counter

counter:
  goal: 3
  when_goal_reached: "The storm engine is fully charged — ready for the reading!"

Open objects/storm-engine.yaml. Keep your goal from 2 through 5. Personalize the device and message; keep the package identity. The authored purple color stays visible in the device.

S09 · 14 / 20

Validate the package

explore-package validate lessons/sessions/s09/student/explorer-package
valid: storm-engine 0.1.0

Fix validation errors before launching.

S09 · 15 / 20

Launch the actual S09 Trail

explore-package trail examples/explorer-packages/nova-character lessons/sessions/s09/student/explorer-package --player "nova-character:nova" --mission-id "count-object-interactions" --name "S09 Power Up a Device"

Run the complete one-line command from the Course Kit folder. Nova arrives in Moon Meadow near the Storm Engine. Move toward its prompt.

S09 · 16 / 20

Add sparks one at a time

At the readable Inspect Storm Engine prompt, press E once. Record count 1. Release and press again for each update. Compare every count with your prediction.

S09 · 17 / 20

Watch the charge grow

More charge cells illuminate on every update. The core grows brighter. At the goal, all cells light and the lightning core and sparks appear. Use the cell shapes and numeric count as well as color.

S09 · 18 / 20

Confirm exact completion

For goal 3, the third interaction displays the authored goal-reached message and completes M09 · Power It Up. No extra press is needed.

Nova beside the fully powered purple Storm Engine, with Count 3 / 3 and mission complete.

Optional: one later press continues counting and keeps the mission complete. There is no reset, decrement, or cap.

S09 · 19 / 20

Why one spark short is not enough

At count 2, one charge cell is still empty and the mission is incomplete. Compare that with exact goal 3. Explain why a loop doing only two updates cannot satisfy your assertion.

S09 · 20 / 20

Explain your tested repair

  • Name the integer counter and its update.
  • Explain range and the off-by-one repair.
  • Explain what your assertion protects.
  • Separate Python, YAML, and Trail state.

The powered device prepares the observatory in our story; its runtime count does not carry into a later session.

Review the Python notes →

Next: S10 · Check the Boundary · Sat, Nov 28, 2026.