S07 · Create a Two-State Prop

What we learned in Python

The Python from session S07, one idea at a time. These notes follow lessons/sessions/s07/student/task-card.md in your course folder.

Back to the S07 slides

1 · Python concept

The idea

Today's Python
BooleanA value with two possibilities: True or False, written with capital first letters.
stateThe value a variable holds at one moment. is_on models whether our lantern is on.
assignmentThe equals sign stores a value. Assigning True changes the local state.
toggle sequencePredict False → True → False → True, matching OFF → ON → OFF → ON.
Python → YAML → TrailLocal Python models the idea. YAML declares toggle.off_color and toggle.on_color. Trail owns runtime session state; every toggle starts off.

2 · Code we wrote

The code

off_color = "blue"
on_color = "gold"

is_on = False
print(is_on, off_color)

is_on = True
print(is_on, on_color)

Run it from the course folder:

python lessons/sessions/s07/student/starter.py

Output:

False blue
True gold

3 · What the code means

Line by line

Each important line
off_color = "blue"Stores the color label for the off observation.
on_color = "gold"Stores the color label for the on observation.
is_on = FalseSets the local Boolean state to False.
print(is_on, off_color)Reads and prints the state and off color; it does not change either value.
is_on = TrueChanges the local variable to True before the second observation.
print(is_on, on_color)Prints True gold after the repair. Printing a color string does not mutate is_on.

4 · Why programmers use this

Beyond this lesson

Represent two states with a Boolean variable and predict how assignment changes that state.

Programs use Boolean state to model a light, a saved setting, or whether an action has happened.

The Sky Lantern signals toward the hidden gate. M07 completes after the toggle changes at least once. Final ON/gold is a story target confirmed by observation, not mission-checked.

5 · What we debugged

A bug worth understanding

is_on = False
print(is_on, on_color)
False gold (no Python exception)

The starter's second line prints gold but leaves is_on = False. Printing on_color does not change state. Repair the assignment before printing; local Python does not control Trail state.

Fixed:

is_on = True
print(is_on, on_color)

6 · Key Python words

Words to know

Vocabulary
BooleanThe two-value type used for True and False.
TrueThe Boolean value modeling ON in this lesson.
FalseThe Boolean value modeling OFF in this lesson.
assignmentStoring a value using =.
stateA value at a particular moment.

7 · Try it yourself

Your turn

  1. Predict all four rows before running: start False/blue, then True/gold, False/blue, True/gold.
  2. Run the starter, explain False gold, repair only the second assignment, and check False blue then True gold.
  3. Validate the package, then interact three times in the Trail. Does M07 remain complete when the lantern is OFF after interaction 2?
  4. Explain the boundary: Python models state, YAML declares colors, and Trail owns runtime session state. Leave the lantern ON/gold for the story and ask your teacher to observe it.