0
0
LLDsystem_design~10 mins

User, Group, Expense classes in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the User class with an __init__ method.

LLD
class User:
    def __init__(self, name):
        self.name = [1]
Drag options to blanks, or click blank then click option'
AUser
Bname
Cself
Dgroup
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning self to self.name
Using class name instead of parameter
Using undefined variable
2fill in blank
medium

Complete the code to add an expense to the Group's expenses list.

LLD
class Group:
    def __init__(self):
        self.expenses = []
    def add_expense(self, expense):
        self.expenses.[1](expense)
Drag options to blanks, or click blank then click option'
Ainsert
Badd
Cappend
Dextend
Attempts:
3 left
💡 Hint
Common Mistakes
Using add (not a list method)
Using extend (adds multiple elements)
Using insert (requires index)
3fill in blank
hard

Fix the error in the Expense class constructor to correctly assign amount.

LLD
class Expense:
    def __init__(self, amount):
        self.amount = [1]
Drag options to blanks, or click blank then click option'
Aamount
Bself.amount
CExpense.amount
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning self.amount to self.amount
Using class name instead of parameter
Assigning zero instead of parameter
4fill in blank
hard

Fill both blanks to create a method in Group that calculates total expenses.

LLD
class Group:
    def __init__(self):
        self.expenses = []
    def total_expense(self):
        return sum(expense.[1] for expense in self.[2])
Drag options to blanks, or click blank then click option'
Aamount
Bexpenses
Ccost
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute name
Iterating over wrong list
Using users instead of expenses
5fill in blank
hard

Fill all three blanks to create a method in User that adds a group and records the user's name.

LLD
class User:
    def __init__(self, name):
        self.name = name
        self.groups = []
    def join_group(self, group):
        self.groups.[1](group)
        print(f"[2] joined [3]")
Drag options to blanks, or click blank then click option'
Aappend
Bself.name
Cgroup.name
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using add instead of append
Printing wrong variables
Not updating groups list