Python provides a built-in function called input() that allows users to enter data while the program is running. This makes programs interactive and dynamic.
🧠 What is User Input in Python?
User input means taking data from the user during program execution.
👉 In simple words:
- Program asks → user types → program uses that data
⚙️ The input() Function
The input() function is used to take input from the user.
🧪 Basic Example
name = input("Enter your name: ")
print("Hello", name)
🔢 Input is Always String
By default, Python takes input as a string.
Example:
age = input("Enter your age: ")
print(type(age))
👉 Output will be:
<class 'str'>
🔢 Converting Input to Number
To use numeric input, we must convert it.
📌 Integer Input
age = int(input("Enter your age: "))
print(age + 5)
📌 Float Input
price = float(input("Enter price: "))
print(price * 2)
🧪 Multiple Inputs Example
x = input("Enter first value: ")
y = input("Enter second value: ")
print("You entered:", x, "and", y)
⚡ User Input with Calculation
a = int(input("Enter number 1: "))
b = int(input("Enter number 2: "))
sum = a + b
print("Sum is:", sum)
🎯 Formatting Input Output
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print(f"My name is {name} and I am {age} years old")
📚 Types of Input Handling
| Type | Function |
|---|---|
| Text input | input() |
| Integer input | int(input()) |
| Float input | float(input()) |
| Boolean logic | comparison after input |
🚀 Where User Input is Used?
User input is used in:
- Login systems 🔐
- Forms 📝
- Calculators 🧮
- Games 🎮
- Data entry apps 📊
🧾 Conclusion
Python user input makes programs interactive by allowing users to send data during execution. It is one of the most important basics in programming.
💡 Final Thought
If you master user input, you can build real-world interactive applications easily.


0 Comments