Bird
0
0

Consider the following code snippet managing turns for 3 players:

medium📝 Analysis Q4 of 15
LLD - Design — Tic-Tac-Toe Game
Consider the following code snippet managing turns for 3 players:
current_player = 2
for _ in range(5):
    current_player = (current_player + 1) % 3
print(current_player)

What will be the printed output?
A0
B1
C2
D3
Step-by-Step Solution
Solution:
  1. Step 1: Initial value

    current_player starts at 2.
  2. Step 2: Iterate 5 times

    Each iteration: current_player = (current_player + 1) % 3.
  3. Step 3: Calculate stepwise

    Turns: 2->0->1->2->0->1 (after 5 increments, current_player is 1).
  4. Step 4: Final output

    Prints 1.
  5. Final Answer:

    1 -> Option B
  6. Quick Check:

    Modulo cycles index correctly [OK]
Quick Trick: Modulo cycles player index after increments [OK]
Common Mistakes:
MISTAKES
  • Miscounting iterations
  • Ignoring modulo wrap-around
  • Assuming index stays constant

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes