-
Hajipur, Bihar, 844101
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
print()
The print()
function is used to show messages or variable values on the screen.
Syntax:
print(value1, value2, ..., sep=' ', end='\n')
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()
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()
.
name = input("Enter your name: ")
age = int(input("Enter your age: "))
Since input()
returns a string, you can cast it like this:
num1 = int(input("Enter number 1: "))
num2 = float(input("Enter number 2: "))
Operation | Function | Returns |
---|---|---|
Display output | print() |
None |
Get input | input() |
str |
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.
Q1: What does the print() function do?
Q2: What does the input() function return?
Q3: Which function would you use to accept data from the user?
Q4: What is the default separator in the print() function?
Q5: What is the default value of end in print()?
Q6: What happens if you try to add two input() values without converting them to int or float?
Q7: Which of the following is true about input()?
Q8: What should be used to convert user input into a number?
Q9: Which function is used to show text to the user?
Q10: What is the result of using end=" " in a print statement?