computer4kids is now ComputerLeap. Same free lessons, same team. Read why we changed our name

← All lessons · 🧑‍💻 Coding Academy

🙋

🎓

⏱ 20 min

Free

Ask Me Anything (input)

Make programs that ask questions and answer back with input().

🎯 What you will learn

  • Ask the user a question with input()
  • Save the answer in a variable
  • Use the answer in a message

👋 Let’s get started!

So far your programs talk, but don’t listen 👂. input() lets your program ask a question and wait for an answer. Now it’s a conversation!

🪜 Step by step

1. ❓ Ask a question

input() shows a question and waits for the answer.

name = input("What is your name? ")
2. 📦 Keep the answer

The answer goes into a variable so you can use it later.

name = input("What is your name? ")
print("Nice to meet you, " + name + "!")
3. 🔁 Ask more

Ask as many questions as you like!

food = input("Favorite food? ")
print(food + " is yummy! 😋")

🧪 Try it!

Change the code and press ▶ Run to see what happens. You can’t break anything!

Chatbot buddy

name = input("Hi! What is your name? ")
pet = input("What pet would you like? ")
print("Wow " + name + ", a " + pet + " sounds amazing! 🐾")

Greeting program

name = input("Your name? ")
greeting = "Hello, " + name
print(greeting)

📖 Key words

Tap a card to flip it over!

input()
Asks a question and waits for an answer 🙋
User
The person using the program 🧑
Prompt
The question shown to the user ❓

🏆 Challenge

Ask for a color, then print: I like too! (Use the answer box: type green)

Challenge

color = input("What is your favorite color? ")

Knowledge Check Quiz

  1. What does input() do?
  2. Where does the answer go?
  3. If the user types Mia, what does the print() line show?
← Previous lesson
Next lesson →