Compare commits
3 Commits
bff068901a
...
a920cf1743
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a920cf1743 | ||
|
|
edc664b5ed | ||
|
|
cf2141779b |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Chapter_09/__pycache__/administration.cpython-312.pyc
|
||||||
8
Chapter_09/9-10_imported_restaurant.py
Normal file
8
Chapter_09/9-10_imported_restaurant.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Exercise 9-10 Imported Restaurant
|
||||||
|
# Learning Objective: Separate, import, and use a class
|
||||||
|
|
||||||
|
from restaurant import Restaurant
|
||||||
|
|
||||||
|
tonys_pizza = Restaurant("Tony's Pizza", "Pizzeria")
|
||||||
|
|
||||||
|
tonys_pizza.describe_restaurant()
|
||||||
9
Chapter_09/9-11_imported_admin.py
Normal file
9
Chapter_09/9-11_imported_admin.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Exercise 9-11 Imported Admin
|
||||||
|
# Learning Objective: Import multiple classes from one module.
|
||||||
|
|
||||||
|
from administration import Users, Admin, Privileges
|
||||||
|
|
||||||
|
george = Admin("George", "Costanza", "9/23/1959", "NY", "Black")
|
||||||
|
george.privileges.privileges = ["can add post", "can delete post", "can ban user", "can unban user", "can create user", "can delete user", "can modify site contents"]
|
||||||
|
george.describe_user()
|
||||||
|
george.privileges.show_privileges()
|
||||||
BIN
Chapter_09/__pycache__/administration.cpython-312.pyc
Normal file
BIN
Chapter_09/__pycache__/administration.cpython-312.pyc
Normal file
Binary file not shown.
45
Chapter_09/administration.py
Normal file
45
Chapter_09/administration.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
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} hair")
|
||||||
|
|
||||||
|
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 Privileges:
|
||||||
|
def __init__(self, privileges=[]):
|
||||||
|
"""Create separate class for privileges """
|
||||||
|
self.privileges = privileges
|
||||||
|
|
||||||
|
def show_privileges(self):
|
||||||
|
""" Print Privileges list """
|
||||||
|
print(f"This user has the following privileges:\n")
|
||||||
|
if self.privileges:
|
||||||
|
for privilege in self.privileges:
|
||||||
|
print(f" - {privilege}")
|
||||||
|
else:
|
||||||
|
print(" - This user has no privileges.")
|
||||||
|
|
||||||
|
class Admin(Users):
|
||||||
|
def __init__(self, first_name, last_name, dob, state, hair_color):
|
||||||
|
""" Initialize Users the add sepeicifc Admin attributes/methods """
|
||||||
|
super().__init__(first_name, last_name, dob, state, hair_color)
|
||||||
|
self.privileges = Privileges()
|
||||||
14
Chapter_09/restaurant.py
Normal file
14
Chapter_09/restaurant.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
class Restaurant:
|
||||||
|
def __init__(self, name, cuisine_type):
|
||||||
|
"""Initialize variables name and cuisine_type, define functions to describe and to open restaurant..."""
|
||||||
|
|
||||||
|
self.name = name
|
||||||
|
self.cuisine_type = cuisine_type
|
||||||
|
|
||||||
|
def describe_restaurant(self):
|
||||||
|
"""Describe the restaurant"""
|
||||||
|
print(f"The restaurant's name is {self.name} and the cuisine served here is {self.cuisine_type}")
|
||||||
|
|
||||||
|
def open_restaurant(self):
|
||||||
|
"""Simulate it being opened"""
|
||||||
|
print(f"{self.name} is now open for business.")
|
||||||
Loading…
x
Reference in New Issue
Block a user