Bird
0
0

Which of the following code snippets will cause an IndentationError in Python?

easy📝 Syntax Q3 of 15
Python - Basics and Execution Environment
Which of the following code snippets will cause an IndentationError in Python?
Adef greet(): print('Hello') print('Welcome')
Bfor i in range(3): print(i) print('Done')
Cif true: print('Yes')
Dwhile false: pass
Step-by-Step Solution
Solution:
  1. Step 1: Review indentation consistency

    Python requires all statements in the same block to have the same indentation level.
  2. Step 2: Identify inconsistent indentation

    for i in range(3): print(i) print('Done') has the second print statement less indented than the first inside the for loop, causing an error.
  3. Final Answer:

    for i in range(3):\n print(i)\n print('Done') -> Option B
  4. Quick Check:

    Inconsistent indentation = IndentationError [OK]
Quick Trick: All lines in a block must align equally [OK]
Common Mistakes:
MISTAKES
  • Mixing tabs and spaces
  • Indenting some lines less than others in a block
  • Forgetting to indent after a colon

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes