S04 · Sat, Oct 10, 2026

Introduce a Character

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

The Moonlit expedition continues

Introduce a Character

Your Moon Compass’s clue led here, to a guide who needs your help. Today you write a Python function that greets anyone by name, and you give the guide a voice.

def greet(name):

Today's mission

M04 · Give Your Character a Voice

Mission: introduce-your-character

Learning target: Define and call greet(name), explain its parameter, and use a traceback to repair an argument problem.

The mission is complete when you speak to the guide and its greeting appears.

Warm-up

A voice in three words

Describe your guide’s voice in three words. Calm, mysterious, and kind? Cheerful, quick, and curious?

Keep those words in mind. You will use them when you write the guide’s greeting.

Recap from S03

f-strings and calls

object_name = "Moon Compass"
print(f"The {object_name} glows.")
  • An f-string fills in the value of each variable inside its braces.
  • print(...) is a function call: a name, then parentheses holding the value it works on.
  • Today you write your own function, and call it the same way.

New today

What is a function?

A function is a named, reusable set of steps. You define it once, then call it as many times as you need.

def greet(name):
    place = "Moonlit Trail"
    print(f"Welcome to {place}, {name}!")

Defining a function does not run it. Nothing prints until a line calls greet.

Read the definition

def greet(name):

The parts of a function definition
defShort for define. It starts a new function.
greetThe function name. You use this exact name to call it.
(name)The parameter: a placeholder for the value each call sends in.
:The colon ends the definition line. The body comes next.
place = ...The body. Every body line is indented by the same four spaces.

Call the function

greet("Ari")

A call runs the function’s body. The value inside the parentheses is the argument. Python puts it into the parameter name.

greet("Ari")
Welcome to Moonlit Trail, Ari!

Inside the body, {name} becomes Ari. Call it again with "Sam", and the same body greets Sam.

Two words, two places

Parameter vs. argument

Where each word belongs
WordWhere it livesExample
parameterIn the definitiondef greet(name):
argumentIn the callgreet("Ari")

name is the parameter. "Ari" is the argument. One function body makes a personalized greeting for each argument.

Python first

The starter

def greet(name):
    place = "TODO: name your setting"
    print(f"Welcome to {place}, {name}!")


greet("Ari")
# TODO: call greet one more time with a name you choose.
python lessons/sessions/s04/student/starter.py

Before you change anything, it prints:

Welcome to TODO: name your setting, Ari!

The visible TODO and the missing second greeting are on purpose. Both are yours to finish.

Predict before running

Write your two lines first

Read the first call and write its exact output. Then choose a name for your second call and predict the line it will print.

“My two lines will be ___ and ___.”

Run Python only after both predictions are written down.

Core path

Setting, second call, run

  1. Replace the TODO value of place with your setting name.
  2. Add one second greet("...") call with a name you choose.
  3. Run the file and compare the output with your prediction.
  4. Checkpoint: explain function, parameter, and argument using your two output lines.

With place = "Moonlit Trail" and a second call greet("Sam"), the output is:

Welcome to Moonlit Trail, Ari!
Welcome to Moonlit Trail, Sam!

The bridge to the world

Python greeting, YAML greeting

From your function to the Trail
Python ideaYAML fieldWhat you see
Personalized greet(name) outputgreetingThe guide speaks one authored greeting

The function runs on your computer. The guide’s greeting is plain text in YAML, and YAML drives the Trail:

# lessons/sessions/s04/student/explorer-package/character/guide.yaml
name: "Moonlit Guide"
greeting: "I'm the Moonlit Guide, explorer — the trail beyond this ridge has gone dark, and I need your help finding a way through."

Your story choice

Write the guide's greeting

Personalize the greeting in one sentence that tells:

  • who the guide is,
  • what the trail problem is, and
  • what help the guide needs.

Use your three voice words. Keep the greeting about as long as the example: a very long greeting ends in … in the speech bubble.

Validate first

Check the package

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

Look for valid: .... If validation fails, fix only the first reported issue and try again.

Launch the Trail

Meet the Moonlit Guide

explore-package trail \
  examples/explorer-packages/nova-character \
  examples/explorer-packages/crystal-lantern \
  lessons/sessions/s04/student/explorer-package \
  --player "nova-character:nova" \
  --mission-id "introduce-your-character" \
  --name "S04 Introduce a Character"

Today’s Trail is the same painted Moon Meadow as S02 and S03. The Moonlit Guide stands in it: a hooded moon-sage with a crescent-moon staff. A small floating speech cue marks the guide until you speak to it.

Speak to the guide

Talk to Moonlit Guide

  1. Walk Nova up to the guide. The prompt reads Talk to Moonlit Guide.
  2. Press E. The whole greeting appears in the guide’s speech bubble, under its Moonlit Guide name tag.
  3. Checkpoint: read your exact greeting from the bubble, and report the M04 result.

The bottom line of the screen repeats the greeting and may end in … when it is too long to fit. Read the greeting from the bubble.

Mission success

M04 complete

Speaking to the guide completes M04. Watch the Mission state row change to Complete.

The Crystal Lantern still glows in the meadow, but it is not today’s target. You do not need to visit it: M04 completes by talking to the guide.

Deliberate debugging

Call greet() with no argument

  1. Save your working second call somewhere in your notes.
  2. Temporarily replace it with a call that has no argument:
greet()
  1. Predict the final line of the traceback before running Python.
  2. Run it. Read the final line for the error type:
TypeError: greet() missing 1 required positional argument: 'name'
  1. Move upward to the first line naming starter.py and its line number.
  2. Restore a call with one name and rerun successfully.

Explain the fix using the words function, parameter, and argument.

Common slips

Three things to check

  • Indentation: both lines in the function body use the same four spaces.
  • Function name: the call must match the definition exactly: greet.
  • Argument: one name string belongs inside the call’s parentheses. Do not add another parameter to hide an error.

If you get stuck

Support and extension paths

Support: compare your code with this recovery shape, then type only the missing pieces:

place = "Moonlit Trail"
print(f"Welcome to {place}, {name}!")
greet("Sam")

The first two lines belong inside the function; the call goes after it. Ask the teacher to point to the location rather than paste a finished file.

Extension: add a third call to the same function with a new name, and predict its exact output first. Do not add another character or package field.

Using AI on this mission

Bounded questions, not full solutions

Explain your intent and write your prediction first. A good question is “What does the final line of this traceback say is missing?” AI may explain a traceback. It may not write your correction or your guide’s greeting. Record your intent, prediction, exact question, suggestion tested, accepted or rejected change, and your own explanation.

Exit check

Three quick answers

  • Functions: In def greet(name):, which word is the parameter? In your second call, what is the argument?
  • Output: Why do your two calls print two different lines from one function body?
  • Debugging: What did the final traceback line say was missing when you called greet()? How did you fix it?

Looking ahead

S05 · Script a Conversation

Your guide has introduced itself. Next session, the guide has more to say, and you help script the conversation.

Close

Wrap up S04

Save your files. Be ready to explain the parameter and the argument in your own code, and to read your guide’s greeting aloud. A correct explanation matters more than finishing every step.

What we learned in Python today →