S05 · Sat, Oct 17, 2026

Script a Conversation

Student slides for session S05. Use these to follow along in class or to recap what to try before next time.

The Moonlit expedition continues

Script a Conversation

The Moonlit Guide introduced itself last session, and it has more to say. Today you store a conversation as an ordered Python list, and the guide gives its briefing one line at a time.

dialogue = ["...", "...", "..."]

Today's mission

M05 · Write a Conversation

Mission: write-a-short-conversation

Learning target: Create an ordered list of 2–3 dialogue lines, retrieve its first and final items, use len(...), and debug order or indexing.

The mission is complete when the guide says its final line.

Warm-up

A tiny story arc

A short briefing has a beginning and an ending. With three lines, it goes:

  • Situation: what the problem is.
  • Clue: what to look for (optional).
  • Task: what the explorer should do next.

Say your guide’s situation and task out loud before you type.

Recap from S04

One value, one name

place = "Moonlit Trail"
greet("Ari")
  • A variable gives one value a name.
  • Last session the guide had one greeting. Today it has several lines, and their order matters.
  • Today one name holds the whole conversation.

New today

What is a list?

A list holds several items in order, inside square brackets, with a comma after each item.

dialogue = [
    "Guide: The dark stretch past the ridge won't clear.",
    "Guide: Three old marker-lights never burned out.",
    "Guide: Find those three lights and lead me home.",
]

Each item is a string. The list keeps them in the order you wrote them.

Read the positions

dialogue[0] and dialogue[-1]

Each index picks one item
IndexPositionIn a briefing
dialogue[0]First itemThe situation
dialogue[1]Second itemThe clue (optional)
dialogue[2]Third itemThe task
dialogue[-1]Final item, counted from the endThe task, for two lines or three

Python counts from 0. A negative index counts from the end, so [-1] is always the final line.

Count the items

len(dialogue)

len(...) counts the items in a list.

print(len(dialogue))
3

Three items have the indexes 0, 1, and 2. The length is one more than the last index.

Python first

The starter

dialogue = [
    "TODO: write an opening line",
    "TODO: write an ending line",
]

# TODO: print the first line with index 0.
# TODO: print the final line with index -1.
print(len(dialogue))
python lessons/sessions/s05/student/starter.py

Before you change anything, it prints only the length:

2

Predict before running

Write four predictions first

Before you run anything, write down:

  1. your exact first line,
  2. your exact final line,
  3. the list length, and
  4. what the guide will say if you press E again after its final line.

Core path

Lines, indexes, run

  1. Replace both TODO strings: an opening line (the situation) and an ending line (a task). Add a middle clue only if it helps the story.
  2. Add print(dialogue[0]) and print(dialogue[-1]) where the TODO comments are.
  3. Run the file and compare the output with your predictions.
  4. Checkpoint: show your first line, final line, and length.

With the three lines from the list slide, the output is:

Guide: The dark stretch past the ridge won't clear.
Guide: Find those three lights and lead me home.
3

Deliberate debugging

Ask for dialogue[3]

  1. Temporarily change dialogue[-1] to dialogue[3].
  2. Predict what happens before you run it.
  3. Run it. Read the final line of the traceback:
IndexError: list index out of range
  1. Move upward to the line naming starter.py.
  2. Restore dialogue[-1] and rerun successfully.

A three-line list has positions 0, 1, and 2. There is no position 3.

Order carries the meaning

Swap two lines

Swap two strings in your list. Predict how the story changes, run it, and read your first and final lines.

Then restore the intended order: situation → clue → task. A task before the situation makes the briefing confusing.

The bridge to the world

Python list, YAML conversation

From your list to the Trail
Python valueYAML fieldWhat you see
Ordered dialogue stringsconversationOne line per E press

Copy only the spoken text, in the same order, without the Guide: label. YAML drives the Trail:

# lessons/sessions/s05/student/explorer-package/character/guide.yaml
name: "Moonlit Guide"
conversation:
  - "The dark stretch past the ridge won't clear."
  - "Three old marker-lights never burned out."
  - "Find those three lights and lead me home."

Validate first

Check the package

explore-package validate lessons/sessions/s05/student/explorer-package

Look for valid: .... Keep 2 or 3 nonblank lines. If validation fails, fix only the first reported issue and try again.

Launch the Trail

Back to the Moonlit Guide

explore-package trail \
  examples/explorer-packages/nova-character \
  examples/explorer-packages/crystal-lantern \
  lessons/sessions/s05/student/explorer-package \
  --player "nova-character:nova" \
  --mission-id "write-a-short-conversation" \
  --name "S05 Script a Conversation"

Today’s Trail is the same painted Moon Meadow as S04, and the Moonlit Guide waits in the same spot. A small floating speech cue stays over the guide until it has said its final line.

Talk through every line

Talk to Moonlit Guide

  1. Walk Nova up to the guide. The prompt reads Talk to Moonlit Guide.
  2. Press E once per line. Each line appears whole in the guide’s speech bubble, under its Moonlit Guide name tag.
  3. Checkpoint: do the lines appear in your list’s order?

The bottom line of the screen repeats each line too.

Mission success

M05 complete

When the guide says its final line, watch the Mission state row change to Complete.

Now test your fourth prediction: press E one more time. The conversation starts again at line one, and M05 stays complete.

The Crystal Lantern still glows in the meadow, but it is not today’s target: M05 completes by talking through the guide’s final line.

Common slips

Three things to check

  • Counting from 0: the first line is [0], not [1].
  • Commas: every line in the list ends with a comma. A missing comma joins two strings into one.
  • Same order: the YAML conversation keeps the order you tested in Python.

If you get stuck

Support and extension paths

Support: keep two lines. On paper, label them index 0 and index 1 before you add the print expressions. Ask the teacher to point to the list position rather than paste a finished file.

Extension: add one middle clue to a two-line conversation, so it reads situation, clue, task. Stay within 2–3 lines.

Using AI on this mission

Bounded questions, not full solutions

Explain your intent and write your prediction first. A good question is “Why does index 3 not exist in my three-line list?” AI may explain one indexing error or say whether your conversation is clear. It may not write or reorder your conversation. Record your intent, prediction, exact question, suggestion tested, accepted or rejected change, and your own explanation.

Exit check

Three quick answers

  • Indexes: Which index shows your first line? Which shows your final line, whether you have two lines or three?
  • Length: What did len(dialogue) print, and why?
  • Debugging: Why did dialogue[3] raise an IndexError, and how did you fix it?

Looking ahead

S06 · Build a Themed Collection

That’s the next session on the class calendar. Keep today’s list ready to explain.

Close

Wrap up S05

Save your files. Be ready to read your conversation aloud in order and to explain [0], [-1], and len(...) in your own code. A correct explanation matters more than finishing every step.

What we learned in Python today →