-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11_coffee_machine_programme_project.py
363 lines (321 loc) · 18.3 KB
/
11_coffee_machine_programme_project.py
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
def cafe_logo():
#flatten the ascii art by Joe Jacques
machine_ascii = (" /~~~~~~~~/|\n / /######/ / |\n / /______/ / |\n ============ /||\n |__________|/ ||\n |\__,,__/ ||"
+ "\n | __,,__ ||\n |_\====/%____||\n | /~~~~\ % / |\n _|/ \%_/ |\n| | | | /\n|__\______/__|/")
#return the variable
return machine_ascii
def coffee_cup():
#flatten the ascii art by James Christopher Goodwin
cup_ascii = " )))\n (((\n +-----+\n | |] ENJOY YOUR DRINK!\n `-----'\n___________\n`---------'"
#return the variable
return cup_ascii
#Create a dictionary for the drinks so that it can be accessed anywhere
MENU = {
"espresso": {
"ingredients": {
"water": 50,
"coffee": 18,
},
"cost": 1.5,
},
"latte": {
"ingredients": {
"water": 200,
"milk": 150,
"coffee": 24,
},
"cost": 2.5,
},
"cappuccino": {
"ingredients": {
"water": 250,
"milk": 100,
"coffee": 24,
},
"cost": 3.0,
}
}
TENDER = {
"quarter": 25,
"dime": 10,
"nickle": 5,
"penny": 1
}
def process_payment(ones, fives, tens, twenty_fives, price):
"""Function checks for correct payment amount.
Accepts payment, returns change if overpayment occurs, or declines payment if underpayment occurs"""
#forego the ones as no conversion is needed
if fives > 0:
fives *= 5
if tens > 0:
tens *= 10
if twenty_fives > 0:
twenty_fives *= 25
#sum of coins into payment and compare to price
payment = (ones + fives + tens + twenty_fives) / 100
if payment == price:
return "Payment Accepted..."
elif payment < price:
return "ERROR: Insufficient Payment"
else:
surplus_cash = (payment - price) * 100
return (int(surplus_cash))
def use_resource(resource_stash, drink_ingredients):
"""Function that selects ingredients for the drink order and updates the resources stocklist
2 Parameters: dictionary of machine resources, 'ingredients' sub-dict key-pairs for any drink
"""
for ingredient in drink_ingredients:
resource_stash[ingredient] -= drink_ingredients[ingredient] #subtract stock in machine by ingredients being used
return resource_stash
def refill(resources_list, resource):
"""Function checks replenishes item based on amount"""
if resource == "water":
resources_list["water"] += 300
return resources_list
elif resource == "milk":
resources_list["milk"] += 200
return resources_list
else:
resources_list["coffee"] += 100
return resources_list
def manager_display(orders_history, profits_history, coin_float, machine_inventory): #Accessed with 'KEY' in order collection input
status = ""
while status != "exit":
status = input("\nManagers Menu:\nORDERS | PROFITS | CASH | INVENTORY | exit\n Type an option OR type 'exit' OR type 'shutdown': ").lower()
if status == "exit":
print("\nExiting Manager Mode...")
break
elif status == "shutdown":
if input("Type 'YES' to confirm: ") == "YES":
return "off"
elif status == "orders":
print("\nManager's Menu > ORDERS")
print(f"\nTotal Orders: {orders_history}")
elif status == "profits":
print("\nManager's Menu > PROFITS")
print(f"\nTotal Profits: ${profits_history}")
elif status == "cash":
print("\nManager's Menu > CASH")
for coin, amount in coin_float.items():
print(f"\n{coin} Totals: {amount}")
elif status == "inventory":
print(f"\nManager's Menu > INVENTORY")
for resource, amount in machine_inventory.items():
print(f"\nItem:\n'{resource}': {amount} units")
else:
print("\nplease choose a valid option").upper()
def cafe_camille():
"""Function that hosts hot drink orders by taking inputs for drink selection and cash payments."""
#Create variable to use for while loop to keep the machine running
machine = "on"
#import the menu variable as a global variable *NOT TO BE CHANGED*
global MENU
global TENDER
#create the base level of resources for the machine
resources = {
"water": 300,
"milk": 200,
"coffee": 100,
}
#declare all counters
total_orders = 0
total_profits = 0
total_coins = {
"quarter": 0,
"dime": 0,
"nickle": 0,
"penny": 0
}
while machine != "off":
#print logo and welcome message
print(cafe_logo() + "\nThis is CAFE CAMILLE")
#print the drinks from the menu
print("The drinks available at this machine are:\n")
for key in MENU:
print(key.upper())
cust_order = input("What drink would you like to order? ").lower()
if cust_order == "key": #PATH TO MANAGER'S CONSOLE
machine = manager_display(total_orders, total_profits, total_coins, resources) #returns "off" or "none" depending on in-function inputs
elif cust_order in MENU: # PATH FOR VALID ITEM SELECTION
low_supplies = [] ### Essential code for upgrade version ###
#check if enough ingredients are available
if cust_order == "espresso": # MENU-OPTION: ESPRESSO
for resource, amount in MENU["espresso"]["ingredients"].items(): # CHECKING INGREDIENT SUPPLIES TO MAKE DRINK
if resources[resource] < amount:
print(f"The {resource} is too low!".upper())
low_supplies.append(resource) ### Essential code for upgrade version ###
#reloop to the start of function or move forward with drink order
if low_supplies:
print("Please choose another drink")
else:
#present the item price
drink_price = MENU["espresso"]["cost"]
print(f"The total price is: ${drink_price} ")
#Collect the payment
coin_quarters = int(input("Insert Amount of Quarters (25 cent): "))
coin_dimes = int(input("Insert Amount of Dimes (10 cent): "))
coin_nickles = int(input("Insert Amount of Nickles (5 cent): "))
coin_pennies = int(input("Insert Amount of Pennies (1 cent): "))
#process the money - ADD INSERTED COINS INTO MACHINE COLLECTION
total_coins["quarter"] += coin_quarters
total_coins["dime"] += coin_dimes
total_coins["nickle"] += coin_nickles
total_coins["penny"] += coin_pennies
#process the money - ADD INSERTED COINS INTO MACHINE COLLECTION
pay_outcome = process_payment(coin_pennies, coin_nickles, coin_dimes, coin_quarters, drink_price)
#provide options for failed payments, surplus cash, and exact cash
if (pay_outcome) == "ERROR: Insufficient Payment": # PATH FOR UNDER-PAYMENT
#remove coins from total coins
print(pay_outcome)
else: #PATH EXCLUSIVELY FOR OVER-PAYMENT AND EXACT PAYMENT
if pay_outcome == "Payment Accepted...": # PATH EXCLUSIVELY FOR EXACT CORRECT PAYMENTS
print(pay_outcome) #prints "payment accepted"
elif type(pay_outcome) != str(): #account for extra change - return change
print(f"Your change is £{pay_outcome/100}...")
#remove coins from total coin inventory to return change
while pay_outcome != 0: #continue until all due change is returned
#check if quarters can be returned as change
if pay_outcome // 25 > 0 and total_coins["quarter"] > 0:
total_coins["quarter"] -= 1 #remove 1 quarter from machine stash
pay_outcome -= 25 #subtract remaining change by the value of current coin taken
elif pay_outcome // 10 > 0 and total_coins["dime"] > 0:
total_coins["dime"] -= 1
pay_outcome -= 10
elif pay_outcome // 5 > 0 and total_coins["nickle"] > 0:
total_coins["nickle"] -= 1
pay_outcome -= 5
elif pay_outcome // 1 > 0 and total_coins["penny"] > 0:
total_coins["penny"] -= 1
pay_outcome -= (1)
print("\nPlease collect your change.\n")
#UPDATE MANAGERS LOG
total_profits += (MENU["espresso"]["cost"])
total_orders += 1
#MAKE THE ESPRESSO - for valid payments only
print("Making your drink...\n".upper())
resources = (use_resource(resources, MENU["espresso"]["ingredients"])) #Update machine inventory
print(coffee_cup())
elif cust_order == "latte": # MENU-OPTION: LATTE
for resource, amount in MENU["latte"]["ingredients"].items(): # CHECKING INGREDIENT SUPPLIES TO MAKE DRINK
if resources[resource] < amount:
print(f"The {resource} is too low!".upper())
low_supplies.append(resource)
#reloop to the start of function or move forward with drink order
if low_supplies:
print("Please choose another drink")
else:
#present the item price
drink_price = MENU["latte"]["cost"]
print(f"The total price is: ${drink_price} ")
#Collect the payment
coin_quarters = int(input("Insert Amount of Quarters (25 cent): "))
coin_dimes = int(input("Insert Amount of Dimes (10 cent): "))
coin_nickles = int(input("Insert Amount of Nickles (5 cent): "))
coin_pennies = int(input("Insert Amount of Pennies (1 cent): "))
#process the money - ADD INSERTED COINS INTO MACHINE COLLECTION
total_coins["quarter"] += coin_quarters
total_coins["dime"] += coin_dimes
total_coins["nickle"] += coin_nickles
total_coins["penny"] += coin_pennies
#process the money - ADD INSERTED COINS INTO MACHINE COLLECTION
pay_outcome = process_payment(coin_pennies, coin_nickles, coin_dimes, coin_quarters, drink_price)
#provide options for failed payments, surplus cash, and exact cash
if (pay_outcome) == "ERROR: Insufficient Payment": # PATH FOR UNDER-PAYMENT
#remove coins from total coins
print(pay_outcome)
else: #PATH EXCLUSIVELY FOR OVER-PAYMENT AND EXACT PAYMENT
if pay_outcome == "Payment Accepted...": # PATH EXCLUSIVELY FOR EXACT CORRECT PAYMENTS
print(pay_outcome) #prints "payment accepted"
#account for extra change - return change
elif type(pay_outcome) != str():
print(f"Your change is £{pay_outcome/100}...")
#remove coins from total coin inventory to return change
while pay_outcome != 0: #continue until all due change is returned
#check if quarters can be returned as change
if pay_outcome // 25 > 0 and total_coins["quarter"] > 0:
total_coins["quarter"] -= 1 #remove 1 quarter from machine stash
pay_outcome -= 25 #subtract remaining change by the value of current coin taken
elif pay_outcome // 10 > 0 and total_coins["dime"] > 0:
total_coins["dime"] -= 1
pay_outcome -= 10
elif pay_outcome // 5 > 0 and total_coins["nickle"] > 0:
total_coins["nickle"] -= 1
pay_outcome -= 5
elif pay_outcome // 1 > 0 and total_coins["penny"] > 0:
total_coins["penny"] -= 1
pay_outcome -= (1)
print("\nPlease collect your change.\n")
else: # PATH EXCLUSIVELY FOR EXACT CORRECT PAYMENTS
print(pay_outcome) #prints "payment accepted"
#UPDATE MANAGERS LOG
total_profits += (MENU["latte"]["cost"])
total_orders += 1
#MAKE THE ESPRESSO - for valid payments only
print("Making your drink...\n".upper())
resources = (use_resource(resources, MENU["latte"]["ingredients"])) #Update machine inventory
print(coffee_cup())
elif cust_order == "cappuccino": # MENU-OPTION: CAPPUCCINO
for resource, amount in MENU["cappuccino"]["ingredients"].items(): # CHECKING INGREDIENT SUPPLIES TO MAKE DRINK
if resources[resource] < amount:
print(f"The {resource} is too low!".upper())
low_supplies.append(resource)
#reloop to the start of function or move forward with drink order
if low_supplies:
print("Please choose another drink")
else:
#present the item price
drink_price = MENU["cappuccino"]["cost"]
print(f"The total price is: ${drink_price} ")
#Collect the payment
coin_quarters = int(input("Insert Amount of Quarters (25 cent): "))
coin_dimes = int(input("Insert Amount of Dimes (10 cent): "))
coin_nickles = int(input("Insert Amount of Nickles (5 cent): "))
coin_pennies = int(input("Insert Amount of Pennies (1 cent): "))
#process the money - ADD INSERTED COINS INTO MACHINE COLLECTION
total_coins["quarter"] += coin_quarters
total_coins["dime"] += coin_dimes
total_coins["nickle"] += coin_nickles
total_coins["penny"] += coin_pennies
#process the money - ADD INSERTED COINS INTO MACHINE COLLECTION
pay_outcome = process_payment(coin_pennies, coin_nickles, coin_dimes, coin_quarters, drink_price)
#provide options for failed payments, surplus cash, and exact cash
if (pay_outcome) == "ERROR: Insufficient Payment": # PATH FOR UNDER-PAYMENT
#remove coins from total coins
print(pay_outcome)
else: #PATH EXCLUSIVELY FOR OVER-PAYMENT AND EXACT PAYMENT
if pay_outcome == "Payment Accepted...": # PATH EXCLUSIVELY FOR EXACT CORRECT PAYMENTS
print(pay_outcome) #prints "payment accepted"
#account for extra change - return change
elif type(pay_outcome) != str():
print(f"Your change is £{pay_outcome/100}...")
#remove coins from total coin stash to return change
print(total_coins) # TESTING/TROUBLESHOOTING MEASURE #
#
while pay_outcome != 0: #continue until all due change is returned
#check if quarters can be returned as change
if pay_outcome // 25 > 0 and total_coins["quarter"] > 0:
total_coins["quarter"] -= 1 #remove 1 quarter from machine stash
pay_outcome -= 25 #subtract remaining change by the value of current coin taken
elif pay_outcome // 10 > 0 and total_coins["dime"] > 0:
total_coins["dime"] -= 1
pay_outcome -= 10
elif pay_outcome // 5 > 0 and total_coins["nickle"] > 0:
total_coins["nickle"] -= 1
pay_outcome -= 5
elif pay_outcome // 1 > 0 and total_coins["penny"] > 0:
total_coins["penny"] -= 1
pay_outcome -= (1)
print("\nPlease collect your change.\n")
else: # PATH EXCLUSIVELY FOR EXACT CORRECT PAYMENTS
print(pay_outcome) #prints "payment accepted"
#UPDATE MANAGERS LOG
total_profits += (MENU["cappuccino"]["cost"])
total_orders += 1
#MAKE THE ESPRESSO - for valid payments only
print("Making your drink...\n".upper())
resources = (use_resource(resources, MENU["cappuccino"]["ingredients"])) #Update machine inventory
print(coffee_cup())
else: #account for input error - while loop re-cycles upon incorrect input
print(" ERROR.\nPlease select from the options provided.")
## LOOP BACK TO BEGINNING##
cafe_camille()