Only Talking, Never Listening?
So far, our programs have been a bit bossy. They tell us things (“Hello!”, “Score is 100”), but they don’t listen to us. Imagine a friend who only talks about themselves and never asks “How are you?”. Annoying, right?
Let’s teach our computer manners.
The Listening Ear: input()
The command to make Python listen is input().
name = input("What is your name? ")
print("Hello", name)
What Happens Here?
input("..."): The computer prints the question and pauses. It waits. It blinks cursor at you.- You type: “Elena” (and hit Enter).
name =: The computer catches what you typed and puts it in thenamebox.print: It uses that name to say hello.
The Robot Waiter
Let’s build a Robot Waiter. It needs to ask what you want to eat.
print("--- ROBOT CAFE ---")
food = input("What would you like to eat? ")
drink = input("And to drink? ")
print("Coming right up!")
print("Here is your", food, "and", drink)
If you run this: Robot: What would you like to eat? You: Pizza Robot: And to drink? You: Slime Juice Robot: Coming right up! Here is your Pizza and Slime Juice
Important Rule: Inputs are Text
When you use input(), the computer treats everything as text (a “string”). Even numbers!
If you type 10 for an age, the computer keeps it as the word “10”, not the number 10. We will learn how to fix that later, but for now, remember: input returns text.
Try It Yourself
Make a “Silly Story” generator. Ask for:
- An animal
- A color
- A funny noise
Then print a sentence like: “The [color] [animal] shouted [noise]!”
This post is part of the Python Basics for Kids series, based on “Python for Kids from 8 to 88”.