user.py
class User():
def __init__(self,first_name,last_name,username,email,location):
self.first_name = first_name.title()
self.last_name = last_name.title()
self.username = username
self.email = email
self.location = location.title()
self.login_attempts = 0
def describe_user(self):
print("\n" + self.first_name + " " + self.last_name)
print(" Username: " + self.username)
print(" Email: " + self.email)
print(" Location: " + self.location)
def greet_user(self):
print("\nWelcome back, " + self.username + "!")
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self.login_attempts = 0
admin.py
from user import User
class Admin(User):
def __init__(self,first_name,last_name,username,email,location):
super().__init__(first_name,last_name,username,email,location)
# Initialize an empty set of privileges.
self.privileges = Privileges([])
class Privileges():
def __init__(self,privileges):
# Initialize the privileges object.
self.privileges = privileges
def show_privileges(self):
for privileges in self.privileges:
print("- " + privileges)
my_admin.py
from admin import Admin
eric = Admin('eric','matthes','e_matthes','e_matthes@example.com','alaska')
eric.describe_user()
eric_privileges = [
'can reset passwords',
'can moderate discussions',
'can suspend accounts',
]
eric.privileges.privileges = eric_privileges
print("\nThe admin " + eric.username + " has these privileges: ")
eric.privileges.show_privileges()