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.
Predict: Read the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.
Run: Run it and compare the result with your prediction.
Investigate: Trace how each line of code connects to what you see.
Make: Build something new using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
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.
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.
I can join pieces of text with + and say where the spaces come from.
Running the lesson
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.
Run: run it live, then change the space inside the quotes and run again. Ask where the space came from.
Investigate: the trace is the key idea, that + adds nothing. Ask a student to read a line aloud as if they were the computer.
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
A NameError mentioning a word the student meant as text. Ask: Is that word inside quotes? Fix: Text needs quotes. Without them Python looks for a name.
Words run together on the screen ("HiAda"). Ask: Where did the space come from in the first program? Fix: A space is a character. Put it inside the quotes, such as "Hi, ".
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
Investigate: Quotes make text. print shows exactly the text it is given, and + joins pieces with nothing in between.
Now you can
Show a line of text with print.
Say why text needs quotes.
Join pieces of text with + and say where the spaces come from.