Completed 9-7 Admin
This commit is contained in:
parent
6e75f60cd3
commit
6153c2d86b
40
9-07_admin.py
Normal file
40
9-07_admin.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# Exercise 9-7 Admin
|
||||||
|
# Learning Objective: Create subclass of User class, add an attribute, add a method, create instance and call method.
|
||||||
|
|
||||||
|
class Users:
|
||||||
|
def __init__(self, first_name, last_name, dob, state, hair_color):
|
||||||
|
"""Initialize User Profile variables"""
|
||||||
|
self.first_name = first_name
|
||||||
|
self.last_name = last_name
|
||||||
|
self.dob = dob
|
||||||
|
self.state = state
|
||||||
|
self.hair_color = hair_color
|
||||||
|
self.login_attempts = 0
|
||||||
|
|
||||||
|
def describe_user(self):
|
||||||
|
"""Prints descriptions of user based on inputs"""
|
||||||
|
print(f"{self.first_name} {self.last_name} was born on {self.dob}, they live in {self.state} and they have {self.hair_color}")
|
||||||
|
|
||||||
|
def greet_user(self):
|
||||||
|
"""Prints personalized greeting to user specified"""
|
||||||
|
print(f"Welcome to this python program, {self.first_name} {self.last_name}!")
|
||||||
|
|
||||||
|
def increment_login_attempts(self):
|
||||||
|
"""Increments Login Attempts by one"""
|
||||||
|
self.login_attempts += 1
|
||||||
|
|
||||||
|
def reset_login_attempts(self):
|
||||||
|
"""Resets login attempts to zero"""
|
||||||
|
self.login_attempts = 0
|
||||||
|
|
||||||
|
class Admin(Users):
|
||||||
|
def __init__(self, first_name, last_name, dob, state, hair_color):
|
||||||
|
super().__init__(first_name, last_name, dob, state, hair_color)
|
||||||
|
self.privileges = ["can add post", "can delete post", "can ban user", "can unban user", "can create user", "can delete user", "can modify site contents"]
|
||||||
|
def show_privileges(self):
|
||||||
|
print(f"This user has the following privileges: {self.privileges}")
|
||||||
|
|
||||||
|
super_dan = Admin("Dan", "Kinter", "03/01/1966", "FL", "Black")
|
||||||
|
|
||||||
|
super_dan.show_privileges()
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user