User Input 🎤⌨️💬
Programs become interactive when they listen to users. Learn input() to make your code talk to humans and respond.
Day 4: User Input — Programs That Listen!
Why Input Matters
Imagine if Google showed the same search results to everyone. Useless right? Apps need to listen to YOU. That's what input() does — it pauses the program and waits for you to type something!
How input() Works
name = input("What is your name? ")
print("Hello", name)
Program asks "What is your name?" You type "Priya". Program says "Hello Priya". That's a real conversation with a computer!
The Big Warning: Input Is Always Text!
Even if you type 21, Python thinks it's the text "21", not the number 21. So if you want to do math, you must convert it!
age = int(input("Your age: "))
print(age + 1)
int() converts "21" text into 21 number. Now age + 1 works perfectly!
Real World Connection
Every time you type in a search bar, fill a form, or enter a password — that's input()! PhonePe asks how much to send. Swiggy asks your address. Your school portal asks your roll number. All input()!
Common Mistakes
Forgetting to store the input.
input("Your name: ") # WRONG — response disappears!
name = input("Your name: ") # CORRECT — saved!
Doing math without converting.
age = input("Age: ")
print(age + 1) # ERROR — "21" + 1 doesn't work!
age = int(input("Age: "))
print(age + 1) # CORRECT!
Mini Challenge
Mini Challenge
Ask the user for their name and age. Then print how old they'll be in 5 years. You need input(), int(), a variable, and print() — all from this week!
Quick Quiz
Q: What does input() always return? A: Text (String) — even if it looks like a number!
Q: How do you convert text "25" to number 25? A: int("25") — wrap it with int()!
Q: User types their name. Which line is correct? A: name = input("Name: ") — always store it!
Key Takeaways
Key Takeaways
- input() pauses the program and waits for the user to type.
- Always store input in a variable or it disappears.
- input() always gives text — use int() or float() for math.
- Every interactive app in the world uses input() to listen to users.
Continue Learning with Rohi
You've used your 3 free Rohi questions. Create a free account to continue learning.