Bird
0
0

What will be printed after running this code?

medium📝 Predict Output Q4 of 15
Python - While Loop

What will be printed after running this code?

num = 1
while True:
    num *= 2
    if num > 10:
        break
print(num)
A10
B16
C8
D12
Step-by-Step Solution
Solution:
  1. Step 1: Trace the loop

    Start with num=1, then multiply by 2 each iteration: 2, 4, 8, 16.
  2. Step 2: Check the break condition

    When num becomes 16, it is greater than 10, so the loop breaks.
  3. Step 3: Print the value

    The printed value is 16.
  4. Final Answer:

    16 -> Option B
  5. Quick Check:

    Loop breaks when num > 10, last num is 16 [OK]
Quick Trick: Multiply until condition met, then break [OK]
Common Mistakes:
MISTAKES
  • Stopping at 10 instead of the first value greater than 10
  • Printing the value before the break
  • Misunderstanding the loop multiplication

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes