-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClean Code Pass 3.py
More file actions
320 lines (267 loc) · 13.8 KB
/
Copy pathClean Code Pass 3.py
File metadata and controls
320 lines (267 loc) · 13.8 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# UNC AI Bootcamp Week 2 Homework
## Challenge Instructions
# Create a food truck ordering system that allows a user to order food from a food truck. The system should allow the user to order multiple items and then print out a receipt with the total cost of the order.
#The system should allow the user to order multiple items and then print out a receipt with the total cost of the order.
#Menu
menu = {
"Snacks": {
"Cookie": .99,
"Banana": .69,
"Apple": .49,
"Granola bar": 1.99
},
"Meals": {
"Burrito": 4.49,
"Teriyaki Chicken": 9.99,
"Sushi": 7.49,
"Pad Thai": 6.99,
"Pizza": {
"Cheese": 8.99,
"Pepperoni": 10.99,
"Vegetarian": 9.99
},
"Burger": {
"Chicken": 7.49,
"Beef": 8.49
}
},
"Drinks": {
"Soda": {
"Small": 1.99,
"Medium": 2.49,
"Large": 2.99
},
"Tea": {
"Green": 2.49,
"Thai iced": 3.99,
"Irish breakfast": 2.49
},
"Coffee": {
"Espresso": 2.99,
"Flat white": 2.99,
"Iced": 3.49
}
},
"Dessert": {
"Chocolate lava cake": 10.99,
"Cheesecake": {
"New York": 4.99,
"Strawberry": 6.49
},
"Australian Pavlova": 9.99,
"Rice pudding": 4.99,
"Fried banana": 4.49
}
}
# 1. Set up order list. Order list will store a list of dictionaries for
# menu item name, item price, and quantity ordered
order_list = [] # This is a list of dictionaries
# Launch the store and present a greeting to the customer
print() # Print a blank line
# 2. Ask the customer for their name and store it in a variable
def welcome_customer():
name = input("What is your name? ")
return name
print("Welcome to the variety food truck.") # \n is a new line character
print() # Print a blank line
# Customers may want to order multiple items, so let's create a continuous
# loop
place_order = True
while place_order:
# Ask the customer from which menu category they want to order
print("From which menu would you like to order? (Choose 5 to exit.)")
print() # Print a blank line
# Create a variable for the menu item number
i = 1 # This will be used to number the menu items
# Create a dictionary to store the menu for later retrieval
menu_items = {} # This will be used to store the menu items
# Print the options to choose from menu headings (all the first level
# dictionary items in menu).
for key in menu.keys(): # Loop through the menu dictionary
print(f"{i}: {key}") # Print the menu item number and menu item name
# Store the menu category associated with its menu item number
menu_items[i] = key # Add the menu item number and menu item name to
# Add 1 to the menu item number
i += 1 # This will be used to number the menu items
print() # Print a blank line
# Get the customer's input
menu_category = input("Type menu number: ")
# Check if the customer's input is equal to 5, if so, exit the program
if menu_category == "5": # Check if the customer's input is equal to 5, if so, exit the program
# Exit the program
print() # Print a blank line
print("Thank you for dining with us!")
exit() # Exit the program
# Check if the customer's input is a number
if menu_category.isdigit(): # Check if the customer's input is a number
# Check if the customer's input is a valid option
if int(menu_category) in menu_items.keys(): # Check if the customer's input is a valid option
# Save the menu category name to a variable
menu_category_name = menu_items[int(menu_category)] # Save the menu category name to a variable
# Print out the menu category name they selected
print(f"You selected {menu_category_name}") # Print out the menu category name they selected
print() # Print a blank line
# Print out the menu options from the menu_category_name
print(f"What {menu_category_name} item would you like to order?") # Print out the menu options from the menu_category_name
print() # Print a blank line
i = 1 # This will be used to number the menu items
menu_items = {} # This will be used to store the menu items
print("Item # | Item name | Price") # Print the menu item number, menu item name, and menu item price
print("-------|--------------------------|-------") # Print a line to separate the menu item number, menu item name, and menu item price
for key, value in menu[menu_category_name].items(): # Loop through the menu dictionary
# Check if the menu item is a dictionary to handle differently
if type(value) is dict: # Check if the menu item is a dictionary to handle differently
for key2, value2 in value.items(): # Loop through the menu dictionary
num_item_spaces = 24 - len(key + key2) - 3 # Calculate the number of spaces for formatted printing
item_spaces = " " * num_item_spaces # Create space strings
print(f"{i} | {key} - {key2}{item_spaces} | ${value2}") # Print the menu item number, menu item name, and menu item price
menu_items[i] = {
"Item name": key + " - " + key2,
"Price": value2
}
i += 1
else:
num_item_spaces = 24 - len(key)
item_spaces = " " * num_item_spaces
print(f"{i} | {key}{item_spaces} | ${value}")
menu_items[i] = {
"Item name": key,
"Price": value
} # Add the menu item number and menu item name to
i += 1 # This will be used to number the menu items
print() # Print a blank line
# Ask customer to input menu item number
menu_item_number = input("Type menu item number: ") # Ask customer to input menu item number
print() # Print a blank line
# 3. Check if the customer typed a number and if it is in the menu items
if menu_item_number.isdigit() and int(menu_item_number) in menu_items.keys(): # Check if the customer typed a number and if it is in the menu items
# Store the menu item name as a variable
menu_item_name = menu_items[int(menu_item_number)]["Item name"]
# Ask the customer for the quantity of the menu item
menu_item_quantity = input(f"How many {menu_item_name}'s would you like to order? (default is 1): ") # Ask the customer for the quantity of the menu item
print() # Print a blank line
# Check if the quantity is a number, default to 1 if not
if menu_item_quantity.isdigit(): # Check if the quantity is a number, default to 1 if not
menu_item_quantity = int(menu_item_quantity) # Convert the quantity to an integer
else:
menu_item_quantity = 1
# Add the item name, price, and quantity to the order list
order_list.append({
"Item name": menu_item_name,
"Price": menu_items[int(menu_item_number)]["Price"],
"Quantity": menu_item_quantity
})
# Return the order list
def get_order_list(order_list):
# Loop through the items in the customer's order
for item in order_list: # Loop through the items in the customer's order
# Store the dictionary items as variables
item_name = item["Item name"]
item_price = item["Price"]
item_quantity = item["Quantity"]
# Calculate the number of spaces for formatted printing
num_item_spaces = 24 - len(item_name) - 3
# Create space strings
item_spaces = " " * num_item_spaces
# Calculate the cost of the order using list comprehension
# Multiply the price by quantity for each item in the order list, then sum()
# and print the prices.
return order_list
# Call the function with the order_list
order_list = get_order_list(order_list)
# Tell the customer their current order
print("Your order so far:") # Tell the customer their current order
print() # Print a blank line
# Loop through the items in the customer's order
for item in order_list: # Loop through the items in the customer's order
# Store the dictionary items as variables
item_name = item["Item name"]
item_price = item["Price"]
item_quantity = item["Quantity"]
# Calculate the number of spaces for formatted printing
num_item_spaces = 24 - len(item_name) - 3
# Create space strings
item_spaces = " " * num_item_spaces
# Print the item name, price, and quantity
print(f"{item_name}{item_spaces} | ${item_price} | {item_quantity}")
print() # Print a blank line
# Calculate the cost of the order using list comprehension
# Multiply the price by quantity for each item in the order list, then sum()
# and print the prices.
total = sum([item["Price"] * item["Quantity"] for item in order_list]) # Calculate the cost of the order using list comprehension
print(f"Sub-total: ${total:.2f}") # Print the total cost of the order
print() # Print a blank line
# Ask the customer if they would like to order anything else
keep_ordering = input("Would you like to keep ordering? (Y)es or (N)o ") # Ask the customer if they would like to order anything else
# Check the customer's input
if keep_ordering.lower() == "y": # Check the customer's input
# Keep ordering
continue
elif keep_ordering.lower() == "n": # Check the customer's input
# Exit the keep ordering question loop
place_order = False
else:
# Tell the customer to try again
print("Please try again.")
# Complete the order
# Since the customer decided to stop ordering, thank them for their order
print() # Print a blank line
print("Thank you for your order! Here is your total:") # Since the customer decided to stop ordering, thank them for their order
print() # Print a blank line
# Calculate the cost of the order using list comprehension
# Multiply the price by quantity for each item in the order list, then sum() and print the prices.
print("Your Total Order:") # Print the order
print() # Print a blank line
print("Item name | Price | Quantity")
print("--------------------------|-------|----------")
# Add your code here
pass
# Tell the customer to try again
print("Please try again.")
# Complete the order
# Since the customer decided to stop ordering, thank them for their order
print() # Print a blank line
print("Thank you for your order! Here is your total:") # Since the customer decided to stop ordering, thank them for their order
print() # Print a blank line
# 11. Calculate the cost of the order using list comprehension
# Multiply the price by quantity for each item in the order list, then sum()
# and print the prices.
# Print the order
print("Your order:") # Print the order
print() # Print a blank line
print("Item name | Price | Quantity")
print("--------------------------|-------|----------")
for item in order_list:
item_name = item["Item name"] # Store the dictionary items as variables
item_price = item["Price"] # Store the dictionary items as variables
item_quantity = item["Quantity"] # Calculate the number of spaces for formatted printing
num_item_spaces = 24 - len(item_name) + 1 # Create space strings
item_spaces = " " * num_item_spaces
print(f"{item_name}{item_spaces} | ${item_price} | {item_quantity}")
print() # Print a blank line
#calculate total order price using list comprehension
total = sum([item["Price"] * item["Quantity"] for item in order_list]) # Calculate the cost of the order using list comprehension
print(f"Total: ${total:.2f}") # Print the total cost of the order
print() # Print a blank line
# Thank the customer for their order and let them know when it will be ready
print("Thank you for your order! It will be ready in 10 minutes.") # Thank the customer for their order and let them know when it will be ready
# Ask the customer is they would like a text alert when their order is ready
print() # Print a blank line
text_alert = input("Would you like a text alert when your order is ready? (Y)es or (N)o ") # Ask the customer is they would like a text alert when their order is ready
# Check the customer's input
if text_alert.lower() == "y": # Check the customer's input
# Thank the customer for opting in to receive text alerts
print("Thank you for opting in to receive text alerts!") # Thank the customer for opting in to receive text alerts
elif text_alert.lower() == "n": # Check the customer's input
# Thank the customer for their order
print("Thank you for your order!") # Thank the customer for their order
else:
# Tell the customer to try again
print("Please try again.")
# Ask the customer if they would like to opt in to receive text alerts for promotions and discounts
# Ask the customer how they would like to pay
# Ask the customer if they would like to leave a tip
# Ask the customer if they would like to receive a receipt
# Exit the program
print() # Print a blank line
print("Thank you for dining with us!") # Exit the program