What is Input and Output?
In programming, input means taking data from the user. This could be their name, age, or anything they type while running the program. Output means showing results or messages to the user.
-
Taking Input from User
Python provides the
input()
function to accept data from the user. It always returns the data as astring
(text), so we may need to convert it to numbers usingint()
orfloat()
functions.Syntax: variable_name = input("Your message here")
🧑‍💻Example :
name = input("Enter your site name: ") print("Thank you for visiting at", name)
Output:
Enter your site name: ShikshaSanchar
Thank you for visiting at ShikshaSanchar
📝 Explanation:
input("Enter your site name: ")
shows a message and waits for user input.The entered value is stored in the variable
name
.print("Thank you for visiting at", name)
For example, if the user enters "ShikshaSanchar", it will display: Thank you for visiting at ShikshaSanchar
Type Conversion with Input
Since
input()
returns text, if we want to take numbers as input (like age, marks, etc.), we convert it like this:age = int(input("Enter your age: ")) height = float(input("Enter your height in meters: "))
Why conversion is needed: Without converting, mathematical operations won't work properly. For example,
input("5") + input("6")
will give56
instead of11
because strings get joined (concatenated). -
Displaying Output
To display information on the screen, we use Python’s
print()
function. It can show strings, numbers, variables, and even expressions.🧑‍💻Example:
print("Welcome to ShikshaSanchar!") x = 10 print("The value of x is", x)
Output:
Welcome to ShikshaSanchar!
The value of x is 10
Printing Multiple Values
We can pass many values inside print()
separated by commas(,) :
🧑‍💻Example:
platform = "ShikshaSanchar"
topic = "Python Programming"
print("Welcome to", platform, "for learning", topic)
Output:
Welcome to ShikshaSanchar for learning Python Programming
Using f-strings (Formatted Strings)
f-strings make it easier to include variables inside a string.
🧑‍💻Example:
platform = "ShikshaSanchar"
course = "Python Basics"
print(f"Welcome to {platform}! Today’s course is {course}.")
Output:
Welcome to ShikshaSanchar! Today’s course is Python Basics.
📝 Explanation
platform = "ShikshaSanchar" assigns the word "ShikshaSanchar" to the
variable platform
.
course = "Python Basics" assigns the words "Python Basics" to the
variable course
.
The print()
function uses an f-string.
An f-string lets us insert variable values directly inside the string using curly brackets
{ }
.
So, {platform}
becomes ShikshaSanchar and {course}
becomes Python
Basics in the output.
Why Input & Output are Important?
- Helps make programs interactive
- Input allows user to give their own data
- Output helps to display results, messages, and errors
- Both are needed in almost every program
Summary:
input()
is used to take input from the userprint()
is used to show output on the screen- Input is always taken as string → convert it when needed
- f-strings are helpful for neat output formatting