Python 01 · Send your first radio signal

Python lesson 1 of 50 · Beginner · About 15 minutes

The moonbase has gone quiet. Start the rescue by getting Pip the rover to send three lines of text to Mission Control.

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

Mission Write, run and change a Python program that prints a short rescue transmission.

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.

Write. Give Python a quoted radio message.. → Run. Python executes each line in order.. → Read. The console shows Pip’s transmission..
Write → Run → Read

Understand the Python in this lesson

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

An instruction in a Python file

Python works through these four instructions from the top down. Choose Run to start the file. Each line begins with print, the name of a built-in tool that sends a message to the output area, sometimes called the console.

What the parentheses do

The opening parenthesis ( begins a call to print. The closing parenthesis ) finishes it. The value inside is the message you are giving to the tool. In print("Moonbase Rescue"), that message becomes the first line on screen.

Quotes mark text

Python calls text a string. The pair of quotes around "Moonbase Rescue" marks where the string starts and ends. The quotes are instructions for Python to read, so the output displays the words inside them.

Punctuation inside a message

The colon in "Pip to Mission Control: habitat lights are on." separates the speaker from the message. It is inside the quotes, so it is part of the text and appears on screen. Spaces and full stops inside the quotes work the same way.

One call, one output line

Each call finishes by moving the output to a new line. Keep the words in the order you want the reader to see them. Changing the order of the instructions changes the order of the story.

How the pieces fit The file controls when each message appears. The print call controls where the message goes. The quoted string controls the words the player sees.

Follow one run, step by step
  1. Run the first instruction.
    Moonbase Rescue Why The first print call displays the mission title.
  2. Read the second and third instructions.
    Pip reports that the habitat lights are on. Mission Control reports that the beacon is quiet. Why The two calls run in sequence and each message gets its own line.
  3. Run the final instruction.
    Next task: check the rover. Why The fourth call displays the final message, then the file ends.

Predict before you run Predict what happens when you swap the first and last print instructions.

Reveal the explanation

The console starts with Next task: check the rover. and ends with Moonbase Rescue. Python follows the new order of the instructions.

Look up Python words and symbols in the course reference

Build the checkpoint

Python skills print(), Strings, Instructions in order.

1. Open a new project

Open a Python editor and create a fresh file. Type the first line yourself. The brackets hold what you want Python to display. The quotation marks mark the beginning and end of the words. This text value is called a string. Save your file as moonbase_01.py if your editor lets you name files.

print("Moonbase Rescue")

2. Write both sides of the call

Add the two radio lines below the title. Pip calls first and Mission Control replies. Python reads these instructions from top to bottom, so the order of the lines in the editor becomes the order of the messages on screen. Keep each print() instruction on its own line.

print("Pip to Mission Control: habitat lights are on.")
print("Mission Control to Pip: the beacon is quiet.")

3. Run it and listen for the last line

Add Pip’s next task and press Run. Look at the output area and read it as a radio script. Try editing the last string and run the program again. The output changes because Python runs the whole file again from the first line. Your new instruction gives a clue about what the program will do next.

print("Next task: check the rover.")
Complete Python checkpoint · moonbase_01.py
print("Moonbase Rescue")
print("Pip to Mission Control: habitat lights are on.")
print("Mission Control to Pip: the beacon is quiet.")
print("Next task: check the rover.")

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–4
Line 1 print("Moonbase Rescue")
Show the message or value in the output.
Line 2 print("Pip to Mission Control: habitat lights are on.")
Show the message or value in the output.
Line 3 print("Mission Control to Pip: the beacon is quiet.")
Show the message or value in the output.
Line 4 print("Next task: check the rover.")
Show the message or value in the output.

Test the mission

  • Before running, say which message you expect to see first.
  • Swap the two radio instructions, run again and observe the new order. Put them back so the conversation still makes sense.
  • Experiment with one extra line announcing that the Workshop is ready to open.

If something goes wrong

Python points near a line of text.
Look for a missing closing quotation mark or bracket. Use straight quotation marks in code.
I can see old output after an edit.
Press Run again and locate the newest lines in the output area.

Mission extension

Write a four-line conversation in which Pip asks permission to enter the Workshop. Keep the person who speaks at the start of each message.