python · level 1 · unit 2 · lesson 4
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
lets your program ask a question.
input is like a waiter taking your order. It asks a question, waits while the person types an answer and presses Enter, then hands back what they typed as a string.
Store the answer in a variable so you can use it. snack = input("Favourite snack? ") puts whatever they type into the box called snack.
Leave a space at the end of your question, inside the quotes, so the answer does not bump into it.
Your program pauses at input until the person presses Enter.
guess first
Someone types crisps. What appears?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
snack = input("Favourite snack? ")
print("Yum, " + snack)
your turn
Your turn. Write the second question.
Write a question asking for a favourite food between the quotes on line 2. End it with a space. We will answer Sam and pancakes.
fix it
The answer went missing. Can you fix it?
- Line 1 asks the question. Where does the answer go?
- The answer is thrown away because no box catches it. Line 2 wants a box called name.
- Put name = in front of input on line 1, then press run.
nailed it
your program asked and listened. :D
inputasks a question and waits for an answer.- It gives back what was typed, as a string.
- Store the answer in a variable to use it later.
new words in your collection
- input
This lesson isn’t saved. A free account remembers every lesson you finish.