User Input (input())

User Input in Python allows a program to take information from the user while the program is running using the input() function.

It helps make programs interactive by letting users enter:

  • Names
  • Numbers
  • Choices
  • Answers

In simple words, the program asks a question and the user responds.

Real-Life Analogy

User input is like a teacher asking a question and a student giving an answer.

  • Teacher asks → “What is your name?”
  • Student answers → “Ravi”

Similarly, a Python program asks and the user responds.

What is the input() Function?

The input() function is used to take data from the keyboard.

Syntax

input()


Usually we add a message:

input("Enter your name: ")

How input() Works

  • Program waits for user input
  • User types a value
  • Presses Enter
  • Value gets stored in a variable

Important:

By default, input() stores data as a string (text).

Example of User Input

name = input("Enter your name: ")
print("Hello", name)


Output

Enter your name: Ravi
Hello Ravi


Example - 1

age = input("Enter your age: ")
print("You are", age, "years old")


Output:

Enter your age: 12
You are 12 years old


Taking Number Input (Using Type Conversion)

Since input() stores text, we use int() or float() for numbers.

Example:

num = int(input("Enter a number: "))
print(num + 5)

Output:

Enter a number: 10
15

int() converts text into a number.

Practical Example

name = input("What is your name? ")
print("Welcome", name)

This is like asking a question and getting an answer.

Example

name = input("Enter your name: ")
age = int(input("Enter your age: "))

print("Hello", name)
print("Next year age:", age + 1)


Output

Enter your name: Ravi
Enter your age: 12

Hello Ravi
Next year age: 13


Common Mistake (Important)

Wrong:

age = input("Enter age: ")
print(age + 1)

 Error

Because input() stores a string.

Correct Way

age = int(input("Enter age: "))
print(age + 1)

 

Common Beginner Mistakes

  • Forgetting input is stored as text
  • Using numbers without int() conversion
  • Missing brackets in input()
  • Spelling errors in variable names


Why User Input is Important

User input in Python helps:

  • Make programs interactive
  • Accept information from users
  • Perform calculations
  • Build real applications


➤ Key Points

  • input() is used to take user input
  • Input is stored as a string by default
  • Use int() or float() for numbers
  • Makes programs interactive and dynamic


➤ Tips for Students

  • Always write a message inside input()
  • Convert number inputs using int()
  • Check brackets and spelling
  • Practice making your own input programs

Check your knowledge

Quickly verify what you've learned from this tutorial.

Question 1

Which function is used to take user input in Python?

input() is used to receive data from the user.

Question 2

By default, input() stores data as:

input() always stores user input as text (string).

Question 3

What is the output if user enters Ravi? name = input("Enter name: ") print("Hello", name)

The entered input is stored and printed with Hello.

Question 4

Why do we use int(input()) ?

int() converts user input from string to integer.

Question 5

What is the output if user enters 10? num = int(input("Enter number: ")) print(num + 5)

int() converts input to a number, then Python adds 5.

Congratulations!

You've successfully mastered the knowledge check for "User Input (input())."

For more questions and practice, click the link below:

Practice More Questions