Bird
0
0

What will this code print?

medium📝 Predict Output Q5 of 15
Python - Basics and Execution Environment
What will this code print?
for i in range(3):
    print(i)
else:
    print('Done')
A0 1 2 Done
B0 1 2
CDone
D0 1 2 3 Done
Step-by-Step Solution
Solution:
  1. Step 1: Understand the for-else structure

    The loop prints numbers 0,1,2. The else runs after loop completes normally.
  2. Step 2: Trace the output

    Prints 0, then 1, then 2, then prints 'Done' after loop ends.
  3. Final Answer:

    0 1 2 Done -> Option A
  4. Quick Check:

    For-else runs else after loop ends = B [OK]
Quick Trick: For-else runs else block after loop finishes normally [OK]
Common Mistakes:
MISTAKES
  • Thinking else runs only on break
  • Expecting 3 in output from range(3)
  • Ignoring else block output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes