🤖 Python Grade 5 · session 4 of 12 · 60 minutes · 🎁 free with an account
Talk to me: asking questions with input()
So far Bolt has done all the talking. Today Bolt listens! You will ask questions, use the answers and build your own chatbot.
A complete lesson · 60 minutes
Teach it, see it, practise it, all on this page.
Open this page with your learner and work down it, or press Teach this lesson to go through it one step at a time on a big screen. Every section has something to do.
- Warm-up3 min
- Warm-up games5 min
- input() asks a question9 min
- Turn text into numbers with int()9 min
- Build a chatbot9 min
- Mad-lib machine7 min
- Age in the future7 min
- Shopkeeper bot5 min
- Quiz5 min
- Set the after-class project1 min
By the end you can
- Ask a question with input()
- Store the answer in a box
- Turn typed numbers into real numbers with int()
- Build a chatbot that uses the answers
Before you start
- Lesson 3: variables and f-strings
Have ready
- This page
- A partner to try your chatbot
Grade 5 · ages 10 and 11 · no experience needed
Warm-up · think first
Someone types 5 and then 3 into a program, and it says the answer is 53. What went wrong?
Show the answer
The program joined them like words. To Python, anything typed in starts as text. Today you'll learn to fix that with int().
Teacher tip: Write "5" + "3" on the board and ask what happens when you glue two words together.
🎮 Warm-up games · 5 quick games
Play with Bolt the robot
Five minutes with Bolt the robot. Vote, say why, then show the answer.
- Which of these is a question a chatbot could not answer from its own memory? (What is 2 + 2? · What's your name? · How many days in a week? · What colour is grass?)
Answer: "What's your name?" is the odd one: the bot has to ask you. That's what input is for. - Would you rather have a chatbot that tells jokes, or one that does your sums? (Tells jokes · Does sums)
Answer: Either! You can build both by the end of today. - In Python, whatever you type into input() starts as text. (Always · Sometimes · Never)
Answer: Always. Even if you type 5, it's the text "5" until you use int(). - What does "5" + "3" make, and what does 5 + 3 make?
Answer: "53" and 8. Text gets joined, and numbers get added. - If you could ask every person one question, what would it be?
Answer: Collect a few: they make great chatbot questions.
Part 1 of 3 · learn, see, practise
input() asks a question
Now it's your turn to talk! input shows a question and waits. Whatever you type goes into a box, ready to use.
input("What's your name? ") shows a question and waits for the answer.
Put the answer in a box: name = input("What's your name? "). Then use the box like any other.
On this page, type your answers in the Input box, one on each line, and then press Run.
🧑🏫 Teacher: type this live with the class
Bolt says hello to you
name = input("What is your name? ")Type a learner's name in the Input box below the code. Press Run. The box name now holds it.
print(f"Hello, {name}!")Bolt greets them by name.
pet = input("What pet would you like? ")Two questions now, so the Input box needs two lines. Add a second answer.
print(f"{name} and a pet {pet}. Great team!")Run it for a few different learners by changing the Input box.
▶ Output
(nothing is printed)
📦 Memory boxes
▶ Output
Favourite food? pizza Yum! I love pizza too.
📦 Memory boxes
'pizza'strChange pizza in the Input box and press Run again. The same code gives a new answer.
Practise it
Start with the warm-up and go as far as you can. The stretch questions are meant to be hard.
1.1 Ask "Your name? " and print exactly: Hi, (the name).
▶ Output
(nothing is printed)
📦 Memory boxes
Model answer (for the teacher)
name = input("Your name? ")
print(f"Hi, {name}")1.2 Ask for a colour, then print: I like (colour) too
▶ Output
(nothing is printed)
📦 Memory boxes
Model answer (for the teacher)
colour = input("Colour? ")
print(f"I like {colour} too")1.3 Ask two questions, for a town and a food. Print: In (town) people love (food)
▶ Output
(nothing is printed)
📦 Memory boxes
Model answer (for the teacher)
town = input("Town? ")
food = input("Food? ")
print(f"In {town} people love {food}")1.4 Ask for a word, then print it shouted in capitals with word.upper(), like HELLO
▶ Output
(nothing is printed)
📦 Memory boxes
Model answer (for the teacher)
word = input("Word? ")
print(word.upper())1.5 Ask for a name, then print how many letters it has: Asha has 4 letters. Use len(name).
▶ Output
(nothing is printed)
📦 Memory boxes
Model answer (for the teacher)
name = input("Name? ")
print(f"{name} has {len(name)} letters")🎁 Free for a year
Make a free account to open the rest of this lesson
Every new account opens every lesson of every course free for a whole year: no payment, no card, nothing to cancel.
Unlocking the rest of this lesson gives you:
- Part 2: Turn text into numbers with int(), with practice at three levels
- Part 3: Build a chatbot, with practice at three levels
- Class activity 1: Mad-lib machine
- Class activity 2: Age in the future
- Class activity 3: Shopkeeper bot
- A 8-question quiz
- After-class project: My chatbot friend
- Homework and a printable practice sheet with answers
- Teach mode and the minute-by-minute teacher's plan
It takes a minute. Anyone under 13 signs up with a parent. The first 2 lessons of every course, every game and all maths practice stay free.
FAQ
Talk to me: asking questions with input(): questions
What does input() do in Python?
It shows a question, waits for the user to type, and gives back what they typed as text.
Why does Python say ValueError with int()?
int() can only turn digits into a number. Typing a word where a number is expected causes this error.
Is a Python chatbot real AI?
Not this one. It follows the steps you wrote, which is a great way to understand how programs talk with people.
Start a conversation
Want a teacher to take this class?
Tell us the learner's age and level. A teacher from our network teaches with these lessons; we confirm timing and price first.
- Tell us the learner’s age or grade and goals
- We’ll suggest a suitable class or learning path
- We’ll confirm format, timing and fees with a parent or guardian