✕ Close
← Numbers and maths

Level 4 · Lesson 28: Programs that listen (input)

Your first .py file →
INTRODUCTION
Programs that listen
input asks a question and waits for the answer.
press Enter ↵
🐍 main.py
Ctrl + Enter runs it too. Esc, then Tab, leaves the code.
Output

Press ▶ Run to see what your program does.

Lesson 28: Programs that listen (input)

Level 4, Python First Steps. Ask a question, wait for the answer, and use it. The new word: input. It follows lesson 27, Numbers and maths. Next comes lesson 29, Your first .py file.

What the lesson explains

Programs that listen. input asks a question and waits for the answer.

input waits. The answer goes into the box called name. On the card: name = input("What is your name? ")

What you do first

Answer the question. Run it and answer. One way to write it: name = input("What is your name? ") / print("Hi " + name). Answer its question with Mia. It prints: What is your name? Mia / Hi Mia.

The code on the screen

input waits. The editor shows 2 lines: name = input("What is your name? ") / print("Hi " + name). Run it, and it prints "What is your name? Sam", "Hi Sam" (answering Sam).

What you practise

Try it, "Answer the question": Run it and answer. One way to write it: name = input("What is your name? ") / print("Hi " + name). Answer its question with Mia. It prints: What is your name? Mia / Hi Mia. Then: Ask for a food, then print Yum!. The editor opens with: food = input("Favourite food? "). One way to write it: food = input("Favourite food? ") / print("Yum, " + food + "!"). Answer its question with pizza. It prints: Favourite food? pizza / Yum, pizza!.

Fix it, "An answer is a string": Print your age next year. The editor opens with: age = input("Age? ") / print(age + 1). One way to write it: age = int(input("Age? ")) / print(age + 1). Answer its question with 10. It prints: Age? 10 / 11.

What PlayBuddy and PlayType say

PlayType: "So far your programs talk. Now they can listen too!"

PlayBuddy: "The program stops and waits for your answer. Then it uses what you wrote."

Help in every lesson

Everything happens on a pretend computer in your browser, so nothing touches your real files. PlayBuddy and PlayType stand beside the board, cheer you on and say when it is your turn.

A green ring shows where to click the first time. After that you do it on your own, and if you slip twice the ring comes back.

Stars

The lesson has 3 things to do. Up to one slip in ten gives three stars, up to one in four gives two, and finishing always gives at least one. Stars and progress are saved in this browser only; there is no account.

About DayOneCode

DayOneCode is an independent learning site, not affiliated with or endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic.