Complete the code to define a class with a constructor.
class User: def __init__(self, name): self.name = [1]
self instead of the parameter name.The constructor assigns the parameter name to the instance variable self.name.
Complete the code to add a method that returns the user's name.
class User: def __init__(self, name): self.name = name def get_name(self): return [1]
name which is not in scope.self instead of the variable.The method returns the instance variable self.name which holds the user's name.
Fix the error in the method that updates the user's name.
class User: def __init__(self, name): self.name = name def update_name(self, new_name): self.name = [1]
name which is undefined here.self.new_name which is not correct.The method should assign the parameter new_name to the instance variable self.name.
Fill both blanks to create a method that checks if the user is active and returns a message.
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'
!= which reverses the condition.User instead of self.name in the message.The method compares self.active to True using ==. It returns a message using self.name.
Complete the code to implement a method that returns a dictionary with the user's name and active status if active.
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
The method returns a dictionary with keys and values: {'name': self.name, 'active': self.active}.