LearnFrenzy
Sign in Take a free test

Lists · Find the Error · Question 6

Bug: one seat booked, a whole column booked Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

Booking seat (0, 1) should mark only one seat. Which statement correctly identifies the bug?

main.py
seats = [["-"] * 3] * 2
seats[0][1] = "X"
for row in seats:
    print(" ".join(row))
  • A join() copies the X
  • B [row] * 2 repeats a reference to the same row list; build rows with [["-"] * 3 for _ in range(2)] Correct
  • C Strings are shared between lists
  • D The index should be seats[1][0]
Correct Answer: Option B

Both rows are one object. A comprehension creates a fresh row each time.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links