← Console bridge: text in, text out

Print text

Show text on the screen with print, and join pieces of text into one line with +.

Chatbots, game menus and error messages all start the same way: a program puts a line of text on the screen.

Until now your programs made pictures. Many programs make text instead. This course is about programs you talk to: they show a line, wait for you, and reply.

PredictRead the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.

Predict

lesson.py
name = "Ada"
print("Hello")
print("Hi, " + name)

print is new. Read the code and decide what appears on the screen.

What will the program show?

RunRun it and compare the result with your prediction.

Run

Run it and compare with your prediction.

Line What it does Why
name = "Ada" Stores the text Ada under the name name Text goes in quotes. The quotes are not shown
print("Hello") Shows Hello and moves to a new line Each print is one line of output
print("Hi, " + name) Joins two pieces of text and shows the result + glues text together. It adds nothing, not even a space
lesson.py
name = "Ada"
print("Hello")
print("Hi, " + name)
Try it yourselfYour edits are saved in this browser.
InvestigateTrace how each line of code connects to what you see.

Investigate

lesson.py
name = "Ada"
print("Hello")
print("Hi, " + name)
print("Hi," + name)
print(name + name)

What does each line show?

One line is missing something.

Output appears in the order the lines run.

Fill in what each line shows.

lineshows
print("Hello")Hello
print("Hi, " + name)
print("Hi," + name)
print(name + name)

This should show three lines, but the program stops with an error. Click the wrong line.

Put the lines in order so the screen shows a line of stars, then Room 12, then Welcome, then a line of stars.

Pieces (click to add)
    Your program

      MakeBuild something new using what you have learned. Expect a few tries; that is normal.

      Make

      Make a four-line sign for your classroom door. Store a name once at the top, use it in at least two of the lines, and run it.

      Try it yourselfYour edits are saved in this browser.
      Need a hint?

      Set name once at the top, then use it in more than one print line.

      Another hint

      Each print is one line: print("Welcome, " + name).

      Print a four-line sign, with your name stored once and used in two lines.

        Run your program. This ticks when your code does all of the above.

        For teachers

        Students meet print, text in quotes, and joining text with +, then make a four-line sign. About 30 minutes.

        Open the teacher guide: answers, solutions, slides and a worksheet.

        Students will be able to

        Running the lesson

        1. Predict: show the two-line program and take a vote. The wrong options are a slip about new lines, a slip about what + does, and a slip about spaces.
        2. Run: run it live, then change the space inside the quotes and run again. Ask where the space came from.
        3. Investigate: the trace is the key idea, that + adds nothing. Ask a student to read a line aloud as if they were the computer.
        4. Make: students choose their own sign. Show a friend a finished one and ask what each line does.

        The hard part (on purpose)

        Telling apart a name and text in quotes. Ask what print would show for the name without quotes.

        When students get stuck

        Stretch and support

        Stretch: Print a box of stars around a message, using more than four print lines.

        Support: Give the sign with one line missing and ask the student to complete it.

        Where it leads

        Next lesson: the program asks a question and uses the answer, so it is no longer the same every time.

        What each step is for

        Now you can
        Next lesson2. Ask and storeAsk a question with input, store the typed answer in a name, and use it in what the program says back.