Python 02 · Give Pip a mission name

Python lesson 2 of 50 · Beginner · About 20 minutes

Pip’s status card has several blank fields. Store the rover, mission and starting station in variables that the radio can reuse.

Pip reaches towards a radio and a coil inside the Habitat, with Earth visible through a round window.

Mission Name three string values and use each value in a status report.

Get ready

Read this as the next checkpoint in Pip’s mission. You can also start with the complete program below.

Open the browser Python editor (opens in a new tab), replace its example with the complete checkpoint below and choose Run. Use Python 3.10 or newer.

Name. A variable names a piece of mission data.. → Store. An assignment puts a value behind that name.. → Report. The radio reads the value each time it needs it..
Name → Store → Report

Understand the Python in this lesson

Read the explanations, then follow the worked example before changing the code.

Give a value a name

In rover = "Pip", rover is a variable name. The right-hand side is the string "Pip". The equals sign assigns the value to the name. Later, Python can use that name to find the value.

Set up the mission first

Python reads the first three assignments before it reaches a report. That gives it a value for each name, mission, rover and station. These assignments prepare information for later instructions, so nothing appears on screen yet.

Read a name or write a word

The last line reads rover without quotes, so Python looks up its value. In the same line, "is ready at the" has quotes, so Python takes those exact words. Putting quotes around rover would make the word rover appear literally.

Separate the pieces with commas

In print("Mission:", mission), the comma separates two values passed to print. Python reads the pieces left to right and puts a space between them by default. The colon in the first piece appears because it belongs to the quoted label.

Reuse a named value

The name station appears in two reports. Both calls read the same value. Try changing the assignment to station = "Workshop" at the top and watch both reports change together.

How the pieces fit The first lines set up the mission details. Later instructions mix fixed labels with those reusable values to make a complete report.

Follow one run, step by step
  1. Run the three assignments.
    The names mission, rover and station are ready to use. Why Each equals sign binds the name on the left to the string on the right.
  2. Read the station report.
    Current station: Habitat Why Print joins a quoted label and the current value of station with a space.
  3. Read the final call.
    Pip is ready at the Habitat Why Print receives a rover value, a fixed phrase and a station value, then displays them in that order.

Predict before you run What would the current station report display if you wrote print("Current station:", "station")?

Reveal the explanation

It would display Current station: station. The quotes make station a literal word. Take away just those quotes to read the variable’s value.

Look up Python words and symbols in the course reference

Build the checkpoint

Python skills Variables, Assignments with =, Reusing values.

1. Give each value a label

Imagine a row of labelled compartments in the Habitat. In Python, a variable name gives you a way to find a value again. The line rover = "Pip" assigns the text "Pip" to the name rover. Type the three assignments at the top before anything tries to use those names.

mission = "Moonbase Rescue"
rover = "Pip"
station = "Habitat"

2. Show a label and a value

Use a comma inside print() to send several values to the output. Python puts a space between them. In print("Rover:", rover), the first part is a string with a colon and the second part retrieves the value stored in rover. Both parts appear on one line.

print("Rover:", rover)

3. Change one place and check both messages

Run the status card. Then change "Habitat" to "Workshop" in the assignment and run again. Both lines that mention the station change together. If you add a new message later, reuse station so the report stays consistent when Pip moves. Restore "Habitat" before your next mission.

print("Current station:", station)
print(rover, "is ready at the", station)
Complete Python checkpoint · moonbase_02.py
mission = "Moonbase Rescue"
rover = "Pip"
station = "Habitat"
print("Mission:", mission)
print("Rover:", rover)
print("Current station:", station)
print(rover, "is ready at the", station)

Read the complete checkpoint line by line

Use this guide beside the checkpoint. Blank lines separate ideas. Indented lines belong to the instruction above them. Lines with brackets still open can carry on below.

Lines 1–7
Line 1 mission = "Moonbase Rescue"
Work out the value on the right, then store it in mission.
Line 2 rover = "Pip"
Work out the value on the right, then store it in rover.
Line 3 station = "Habitat"
Work out the value on the right, then store it in station.
Line 4 print("Mission:", mission)
Show the message or value in the output.
Line 5 print("Rover:", rover)
Show the message or value in the output.
Line 6 print("Current station:", station)
Show the message or value in the output.
Line 7 print(rover, "is ready at the", station)
Show the message or value in the output.

Test the mission

  • Read and point to the stored value and the variable name in each assignment.
  • Temporarily change Pip’s name to Beep. Count how many output lines change when you run the program.

If something goes wrong

The output says rover instead of Pip.
Use rover without quotation marks when you want the saved value.
Python reports an undefined name.
Check spelling and capital letters. The assignment must run before the print instruction.

Mission extension

Add a variable called destination with the value "Beacon". Print the starting station and destination on one line.