-
Notifications
You must be signed in to change notification settings - Fork 0
/
maquina_de_cafe.py
66 lines (56 loc) · 1.71 KB
/
maquina_de_cafe.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
class NoElementsException(Exception):
pass
class NoSugarException(Exception):
pass
class NoCoinException(Exception):
pass
class CoffeeMachinePlus:
def __init__(self):
self.coins = 0
self.sugar = 0
self.sugar_level_seleted = 0
self.resources = {
'coffee': 0,
'milk': 0,
'tea': 0,
}
self.recipies = {
'coffee_alone': {
'coffee': 30,
},
'coffee_with_milk': {
'coffee': 30,
'milk': 20,
},
'coffee_alone_with_sugar': {
'coffee': 30,
'sugar': 10,
},
'coffee_double': {
'coffee': 60,
},
'tea_simple': {
'tea': 10,
},
}
def insert_coin(self):
self.coins += 1
def sugar_level(self, level):
self.sugar_level_seleted = level
def add_resource(self, type, amount):
self.resources[type] += amount
def add_sugar(self, amount):
self.sugar += amount
def get_product(self, product_type):
if self.coins == 0:
raise NoCoinException()
product_recipe = self.recipies[product_type]
for product in product_recipe.keys():
if self.resources[product] < product_recipe[product]:
raise NoElementsException('Missing {}'.format(product))
if self.sugar < self.sugar_level_seleted * 3:
raise NoSugarException()
self.coins -= 1
self.sugar -= self.sugar_level_seleted * 3
for product in product_recipe.keys():
self.resources[product] -= product_recipe[product]