Python Input and Output


Python provides simple functions to take input from the user and output data to the screen.

  • 📥 Input → Collect data from the user using the input() function

  • 📤 Output → Display data using the print() function


🖨️ Output in Python – print()

The print() function is used to show messages or variable values on the screen.

Syntax:

print(value1, value2, ..., sep=' ', end='\n')
✅ Examples:
print("Hello, World!")  
print("Name:", "John")  
print("Hello", end=" ")  
print("World!")
  • sep: Separator between values (default is space)

  • end: What to print at the end (default is newline \n)


🎤 Input in Python – input()

The input() function reads a line of text entered by the user.

Syntax:

variable = input("Enter something: ")
  • The input is always received as a string, even if the user types a number.

  • You can convert it to int/float using int() or float().

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

🔄 Type Casting with Input

Since input() returns a string, you can cast it like this:

num1 = int(input("Enter number 1: "))
num2 = float(input("Enter number 2: "))

🧠 Summary Table

Operation Function Returns
Display output print() None
Get input input() str

Practice Questions

Q1. Write a Python program to display your name using the print() function.

Q2. Write a Python program to take the user's name as input and greet them with a message.

Q3. Write a Python program to accept two numbers from the user and display their sum.

Q4. Write a Python program to ask the user to enter their age and display it with a message like “You are 25 years old”.

Q5. Write a Python program to use end=' ' and print two words on the same line.

Q6. Write a Python program to accept a float number from the user and print its type.

Q7. Write a Python program to take input for a subject name and print a sentence using it, like “I love Math”.

Q8. Write a Python program to ask the user to enter 3 words and print them separated by commas using sep=','.

Q9. Write a Python program to take a string input and convert it to uppercase before printing.

Q10. Write a Python program to get two numbers from the user and display their product.


Python Input and Output Quiz

Q1: What does the print() function do?

A. Takes input from the user
B. Displays output to the screen
C. Stores data
D. Converts data types

Q2: What does the input() function return?

A. Integer
B. Float
C. String
D. Boolean

Q3: Which function would you use to accept data from the user?

A. print()
B. input()
C. scanf()
D. read()

Q4: What is the default separator in the print() function?

A. Comma
B. Colon
C. Space
D. New line

Q5: What is the default value of end in print()?

A. Space
B. Comma
C. Newline
D. Dot

Q6: What happens if you try to add two input() values without converting them to int or float?

A. They will be added as integers
B. They will be multiplied
C. They will be concatenated as strings
D. Error will occur

Q7: Which of the following is true about input()?

A. It returns boolean
B. It automatically converts to int
C. It returns the user input as a string
D. It is used for output

Q8: What should be used to convert user input into a number?

A. bool()
B. str()
C. int() or float()
D. input()

Q9: Which function is used to show text to the user?

A. scan()
B. echo()
C. print()
D. write()

Q10: What is the result of using end=" " in a print statement?

A. It ends the output early
B. It prints text in the next line
C. It continues printing on the same line
D. It adds a comma

Go Back Top