Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q14 of 15
Python - Variables and Dynamic Typing
Find the error in this code snippet:
my_var = 'hello'
if type(my_var) == str:
print('It is a string')
AMissing colon after if statement
BIndentation error in print statement
CVariable name is invalid
DIncorrect use of type() function
Step-by-Step Solution
Solution:
  1. Step 1: Check the if statement syntax

    The if statement has a colon and uses type() correctly, so no error there.
  2. Step 2: Check indentation of the print statement

    In Python, the code inside if must be indented. Here, print is not indented, causing an indentation error.
  3. Final Answer:

    Indentation error in print statement -> Option B
  4. Quick Check:

    Indent inside if blocks [OK]
Quick Trick: Indent code inside if statements [OK]
Common Mistakes:
MISTAKES
  • Forgetting to indent after if
  • Misusing type() comparison
  • Missing colon after if

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes