-
Hajipur, Bihar, 844101
In Python, you can take input from users using the built-in input()
function. It lets your program interact with users during runtime.
Use input()
to ask the user to type something:
name = input("Enter your name: ")
print("Hello", name)
✅ The input from the user is always returned as a string.
Since input()
returns a string, you’ll often need to convert it to int or float:
age = input("Enter your age: ")
age = int(age)
print("You will be", age + 1, "next year.")
price = float(input("Enter the price: "))
print("Total price after tax:", price * 1.18)
x = int(input("Enter first number: "))
y = int(input("Enter second number: "))
print("Sum is:", x + y)
Always validate the input if needed:
data = input("Enter a number: ")
if data.isdigit():
print("It's a number!")
else:
print("Invalid input")
For multiple lines, you can loop:
print("Enter lines (type 'end' to finish):")
lines = []
while True:
line = input()
if line.lower() == "end":
break
lines.append(line)
Q1. Write a Python program to ask the user to enter their first and last name, then print the full name.
Q2. Write a Python program to take input of two numbers and print their product.
Q3. Write a Python program to ask for temperature in Celsius and convert it to Fahrenheit.
Q4. Write a Python program to ask the user for their favorite color and display it in a sentence.
Q5. Write a Python program to input a number and check if it is even or odd.
Q6. Write a Python program to ask the user to enter their age, convert it to an integer, and check if they are 18 or older.
Q7. Write a Python program to take 3 float inputs and print their average.
Q8. Write a Python program to input a name and print its length using len()
.
Q9. Write a Python program to read two numbers from the user and print the larger one.
Q10. Write a Python program to input a string and print it in uppercase.
Q1: What is the default data type returned by input()?
Q2: Which function is used to take input from a user?
Q3: How do you convert user input into an integer?
Q4: What does int(input()) do?
Q5: What will happen if a non-number is converted using int()?
Q6: Which input is best for decimal values?
Q7: Which method can check if input is a number?
Q8: What does this code do? input("Enter value: ")
Q9: Which of these is True about input()?
Q10: What should you do before using user input in calculations?