Bird
Raised Fist0

Given the code below, what will be the value of current_player after 5 turns?

medium📝 Analysis Q13 of Q15
LLD - Design — Tic-Tac-Toe Game
Given the code below, what will be the value of current_player after 5 turns?
players = ['Alice', 'Bob', 'Charlie']
current_index = 0
for _ in range(5):
    current_index = (current_index + 1) % len(players)
current_player = players[current_index]
ACharlie
BAlice
CBob
DIndexError
Step-by-Step Solution
Solution:
  1. Step 1: Calculate index after each turn

    Starting at 0, increment 5 times with modulo 3: Turns: 1->1, 2->2, 3->0, 4->1, 5->2
  2. Step 2: Determine player at final index

    Index 2 corresponds to 'Charlie'. But since loop increments before assignment, after 5 turns current_index is 2.
  3. Final Answer:

    Charlie -> Option A
  4. Quick Check:

    5 turns cycle index to 2 = Charlie [OK]
Quick Trick: Count modulo steps to find final player [OK]
Common Mistakes:
MISTAKES
  • Off-by-one error in counting turns
  • Confusing index with player name
  • Assuming index resets incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes