Lesson 3: Input and Output
Programs that only show the same output every time are boring. The input() function lets your program ask the user a question and use their answer!
Key Concepts
Getting Input
input('What is your name? ') pauses the program, shows the question, and waits for the user to type something and press Enter. Whatever they type comes back as a string.
Storing Input
You almost always store input in a variable: name = input('What is your name? '). Now you can use name anywhere in your program.
Numbers from Input
input() always returns text (a string). To use it as a number, wrap it in int(): age = int(input('How old are you? ')). This converts the text '10' into the number 10.
🆕 Try It: Live Python
Type your answers when prompted!
✅ Check Your Understanding
1. What does input() do?
2. Why do we use int() with input()?
3. name = input('Your name: ') stores the answer in...