0
0
LLDsystem_design~10 mins

Class responsibilities and behavior 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 define a class with a constructor.

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

Complete the code to add a method that returns the user's name.

LLD
class User:
    def __init__(self, name):
        self.name = name
    
    def get_name(self):
        return [1]
Drag options to blanks, or click blank then click option'
Aself.name
Bname
CUser.name
Dself
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the parameter name which is not in scope.
Returning self instead of the variable.
3fill in blank
hard

Fix the error in the method that updates the user's name.

LLD
class User:
    def __init__(self, name):
        self.name = name
    
    def update_name(self, new_name):
        self.name = [1]
Drag options to blanks, or click blank then click option'
Aname
Bself.new_name
Cnew_name
DUser.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using name which is undefined here.
Using self.new_name which is not correct.
4fill in blank
hard

Fill both blanks to create a method that checks if the user is active and returns a message.

LLD
class User:
    def __init__(self, name, active):
        self.name = name
        self.active = active
    
    def status(self):
        if self.active [1] True:
            return '[2] is active'
        else:
            return '[2] is inactive'
Drag options to blanks, or click blank then click option'
A==
B!=
CUser
Dself.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using != which reverses the condition.
Using User instead of self.name in the message.
5fill in blank
hard

Complete the code to implement a method that returns a dictionary with the user's name and active status if active.

LLD
class User:
    def __init__(self, name, active):
        self.name = name
        self.active = active
    
    def info(self):
        if self.active:
            return {'name': [1], 'active': self.active}
        else:
            return None
Drag options to blanks, or click blank then click option'
A{
Bself.name
C'name'
D}
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names as keys without quotes.
Not returning a dictionary structure.