Python: Input
Interact with your users by capturing data from the keyboard.
The Hook
If print() is the Megaphone (Output), then
input() is the Microphone (Input).
It pauses the program and opens a "listening ear" to wait for the user to type something. Whatever they type gets stored instantly in a variable box.
Pauses
Captured
Question & Answer
See how we ask a question and save the user's response.
Predict
If I type "Red" when prompted, what appears?
print("I like " + color)
Live Python Lab
Interactive Input Session.
🥉 Favourite Food
Modify the code below:
- Ask for Favourite Food (instead of City).
- Change the output to say
"I love [food] too!"
🥈 Fixed Assignment
The code below is trying to store the input, but it's backwards!
🥇 Security System
Ask for a PIN, confirm it, and enable the system.
- Store first input in
pin1 - Store second input in
pin2 - Print
"System Armed"