Bird
0
0

Identify the error in this code:

medium📝 Debug Q14 of 15
Python - Basics and Execution Environment
Identify the error in this code:
if True:
print('Yes')
    print('Still Yes')
ASyntaxError because of missing colon
BIndentationError due to inconsistent indentation
CNo error, code runs fine
DNameError due to undefined variable
Step-by-Step Solution
Solution:
  1. Step 1: Check indentation after if statement

    Lines inside the if block must be indented equally.
  2. Step 2: Identify inconsistent indentation

    The first print is not indented, the second print is indented. This causes an IndentationError.
  3. Final Answer:

    IndentationError due to inconsistent indentation -> Option B
  4. Quick Check:

    Inconsistent indentation = IndentationError [OK]
Quick Trick: All lines in a block must have same indentation [OK]
Common Mistakes:
MISTAKES
  • Thinking missing colon causes error here
  • Assuming code runs without indentation
  • Confusing IndentationError with NameError

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes