Bird
Raised Fist0

Identify the error in this code snippet:

medium📝 Analysis Q6 of Q15
LLD - Design — Splitwise (Expense Sharing)
Identify the error in this code snippet:
class Group:
    def __init__(self):
        self.users = set()
    def add_user(self, user):
        self.users.append(user)
AUsing set instead of list for users
BUsing append method on a set
CMissing return statement in add_user
DIncorrect constructor name
Step-by-Step Solution
Solution:
  1. Step 1: Check data structure methods

    Set objects do not have append method; they use add() instead.
  2. Step 2: Identify method misuse

    Calling append on a set causes an error.
  3. Final Answer:

    Using append method on a set -> Option B
  4. Quick Check:

    Set uses add(), not append [OK]
Quick Trick: Sets use add(), lists use append() [OK]
Common Mistakes:
MISTAKES
  • Confusing append and add methods
  • Thinking append works on all collections
  • Ignoring method errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes