Bird
0
0

What is the output of this code?

medium📝 Predict Output Q13 of 15
Python - For Loop

What is the output of this code?

for num in [1, 2, 3]:
    if num == 4:
        break
else:
    print("No break encountered")
ANo output
BNo break encountered
Cbreak
DError
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the loop and condition

    The loop checks if num == 4. Since 4 is not in the list, break never runs.
  2. Step 2: Check the else block execution

    Because the loop completes without break, the else block runs and prints "No break encountered".
  3. Final Answer:

    No break encountered -> Option B
  4. Quick Check:

    Else runs if no break, so prints message [OK]
Quick Trick: Else runs only if break never happens [OK]
Common Mistakes:
MISTAKES
  • Assuming else never runs
  • Thinking break triggers else
  • Expecting error due to missing break

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes