-
Notifications
You must be signed in to change notification settings - Fork 0
/
coffee_machine.py
37 lines (30 loc) · 1.19 KB
/
coffee_machine.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
from menu import Menu
class CoffeeMachine:
def __init__(self):
self.resources ={
"water": 300,
"milk": 200,
"coffee" : 100
}
self.profit = 0
def get_resources(self):
items = []
for resource, quantity in self.resources.items():
items.append(f"{resource.title()}: {quantity}\n")
return "".join(items)
def are_resources_enough(self, drink):
missing_ingredients = []
for resource, quantity in self.resources.items():
if quantity < drink.ingredients[resource]:
missing_ingredients.append(resource)
return len(missing_ingredients) == 0, missing_ingredients
def get_missing_resources(self, missing_ingredients):
display_missing = {
1: "Sorry! There's not enough {}!",
2: "Sorry! There's not enough {} and {}",
3: "Sorry! There's not enough {}, {} and {}",
}
return display_missing[len(missing_ingredients)].format(*missing_ingredients)
def deduct_resources(self, drink):
for ingredient, quantity in drink.ingredients.items():
self.resources[ingredient] -= quantity