Bird
0
0

What will be the output of this code if the user types 25 when asked?

medium📝 Predict Output Q13 of 15
Python - Input and Output
What will be the output of this code if the user types 25 when asked?
age = input('Enter your age: ')
print(age + 5)
A30
B255
C5
DTypeError
Step-by-Step Solution
Solution:
  1. Step 1: Understand input() returns a string

    The variable age will be the string '25', not the number 25.
  2. Step 2: Analyze the print statement

    age + 5 attempts to add a string and an integer. In Python, this causes a TypeError, but if the code was print(age + '5'), it would concatenate to '255'. Since the code is print(age + 5), it raises a TypeError.
  3. Final Answer:

    TypeError -> Option D
  4. Quick Check:

    String + int causes TypeError [OK]
Quick Trick: input() returns text; convert to int before adding numbers [OK]
Common Mistakes:
MISTAKES
  • Assuming input() returns number
  • Trying to add int to string without conversion
  • Expecting automatic type conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes