Bird
0
0

Given a game system supporting multiple players, what will be the output of this Python snippet?

medium📝 Analysis Q13 of 15
LLD - Design — Tic-Tac-Toe Game
Given a game system supporting multiple players, what will be the output of this Python snippet?
players = ['Alice', 'Bob', 'Carol']
turns = 5
for i in range(turns):
    current = players[i % len(players)]
    print(current)
ABob Carol Alice Bob Carol
BAlice Bob Carol Carol Carol
CAlice Alice Alice Alice Alice
DAlice Bob Carol Alice Bob
Step-by-Step Solution
Solution:
  1. Step 1: Understand modulo for cycling players

    The modulo operator cycles index through player list length (3).
  2. Step 2: Trace each iteration's player

    i=0 -> Alice, i=1 -> Bob, i=2 -> Carol, i=3 -> Alice, i=4 -> Bob.
  3. Final Answer:

    Alice Bob Carol Alice Bob -> Option D
  4. Quick Check:

    Modulo cycles players = Alice Bob Carol Alice Bob [OK]
Quick Trick: Use modulo to cycle through players repeatedly [OK]
Common Mistakes:
MISTAKES
  • Not using modulo causes index errors
  • Assuming players list is longer than turns
  • Confusing player order in output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes