Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q13 of 15
Python - Exception Handling Fundamentals
What will be the output of this code?
try:
    num = int('abc')
except ValueError:
    print('Value error caught')
except TypeError:
    print('Type error caught')
AValue error caught
BType error caught
CNo output
DProgram crashes with ValueError
Step-by-Step Solution
Solution:
  1. Step 1: Identify the error raised by int('abc')

    Trying to convert 'abc' to int raises a ValueError.
  2. Step 2: Match the error with except blocks

    The ValueError is caught by the first except block, so it prints 'Value error caught'.
  3. Final Answer:

    Value error caught -> Option A
  4. Quick Check:

    int('abc') = ValueError caught [OK]
Quick Trick: Match error type to except block to find output [OK]
Common Mistakes:
  • Confusing ValueError with TypeError
  • Thinking program crashes without except
  • Assuming no output if error caught

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes