Bird
0
0

Identify the bug in the following player turn management code snippet:

medium📝 Analysis Q14 of 15
LLD - Design — Tic-Tac-Toe Game
Identify the bug in the following player turn management code snippet:
players = ['Anna', 'Ben', 'Cara']
current_index = 0
while True:
    print(players[current_index])
    current_index += 1
APlayers list is empty
BThe loop never ends
Ccurrent_index will go out of range causing an error
DPrint statement is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Analyze index increment without wrap

    current_index increases endlessly without modulo, so it will exceed list length.
  2. Step 2: Identify resulting error

    Accessing players[current_index] beyond list size causes IndexError.
  3. Final Answer:

    current_index will go out of range causing an error -> Option C
  4. Quick Check:

    Missing modulo causes index error [OK]
Quick Trick: Always wrap index with modulo to avoid errors [OK]
Common Mistakes:
MISTAKES
  • Ignoring infinite loop problem
  • Assuming list is empty
  • Thinking print causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes