Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q6 of 15
Python - Variables and Dynamic Typing
Find the error in this code snippet:
num = 10
num = 'twenty'
print(num + 5)
ANameError because num is undefined
BSyntaxError due to invalid assignment
CTypeError because you cannot add str and int
DNo error, output will be 'twenty5'
Step-by-Step Solution
Solution:
  1. Step 1: Analyze variable assignments

    num is first int 10, then reassigned to string 'twenty'.
  2. Step 2: Check the operation print(num + 5)

    Adding string and int causes TypeError in Python.
  3. Final Answer:

    TypeError because you cannot add str and int -> Option C
  4. Quick Check:

    Type mismatch in addition = TypeError [OK]
Quick Trick: Cannot add string and integer directly [OK]
Common Mistakes:
MISTAKES
  • Expecting implicit type conversion
  • Thinking no error occurs when mixing types
  • Confusing assignment errors with operation errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes