-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimports.py
More file actions
109 lines (86 loc) · 4.2 KB
/
imports.py
File metadata and controls
109 lines (86 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# from printing_functions import User #9-12: I have confirmed that this works for double imports.
class Restaurant(): # 9-10: Show I can import this code into another sheet.
"""Models a restaurant."""
def __init__(self, restaurant_name, cuisine_type, number_served=0):
"""Initialize name, cuisine attributes, and number served."""
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
self.number_served = number_served
def describe_restaurant(self):
"""Prints restaurant name and cuisine type."""
print('The restaurant is ' + self.restaurant_name + ' and serves ' + self.cuisine_type + ' cuisine.')
def open_restaurant(self):
"""Prints that the restaurant is open."""
print('The restaurant is now open for business!')
def set_number_served(self, set_number):
"""Sets the number served with a new number."""
self.number_served = set_number
def increment_number_served(self, increment_number):
"""Increments the current number served"""
self.number_served += increment_number
class User(): # 9-11: Import this into another python script and show it works correctly.
"""Models a user."""
def __init__(self, first_name, last_name, gender, age, login_attempts=0):
"""Stores user information."""
self.first_name = first_name
self.last_name = last_name
self.gender = gender
self.age = age
self.login_attempts = login_attempts
def describe_user(self):
"""Prints information about the user."""
print(self.first_name.title() + ' ' + self.last_name.title()
+ ' is a ' + self.gender + ' aged ' + str(self.age) + '.')
def greet_user(self):
"""Prints a welcoming message to the user."""
print('Hello ' + self.first_name.title() + ' ' + self.last_name.title() + '!')
def increment_login_attempts(self):
"""Increments login_attempts by 1"""
self.login_attempts += 1
def reset_login_attempts(self):
"""Resets the number of login_attempts"""
self.login_attempts = 0
class Admin(User):
"""A child class of the parent class User."""
def __init__(self, first_name, last_name, gender, age, login_attempts=0):
"""Initialize attributes of the parent class.
Then initializes an attribute (privileges) specific to the Admin class."""
super().__init__(first_name, last_name, gender, age, login_attempts)
self.privileges = Privileges() # This is a class. Make sure to add the () at the end.
class Privileges():
"""Contains the privileges for the Admin class."""
def __init__(self, reputation=500, privileges=['can add post', 'can delete post', 'can ban user']):
self.privileges = privileges
self.reputation = reputation
def show_privileges(self):
"""Print the privileges that the Admin class has."""
print('The admin has the following privileges: ' + str(self.privileges))
def show_reputation(self):
"""Print the reputation that the Admin class has."""
print('The admin has the following reputation: ' + str(self.reputation))
if self.reputation > 800:
print('\tThis admin is popular!')
def set_reputation(self, new_reputation):
"""Upgrades the reputation that the Admin class has based on input."""
max_reputation = 999
min_reputation = 0
if new_reputation > max_reputation:
self.reputation = max_reputation
elif new_reputation < min_reputation:
self.reputation = min_reputation
else:
self.reputation = new_reputation
def make_car(manufacturer, model, **car_info): # 8-14
"""Builds a dictionary containing everything we know about a car."""
car = {}
car['manufacturer'] = manufacturer
car['model'] = model
for key, value in car_info.items():
car[key] = value
return car
def make_album(artist_name, album_title, track_count=''): # 8-7
"""Returns a dictionary of an album's artist, title, and track count (optional)."""
album = {'artist': artist_name.lower(), 'title': album_title.lower()}
if track_count:
album['tracks'] = track_count
return album