-
Notifications
You must be signed in to change notification settings - Fork 0
/
coffee_machine.py
162 lines (144 loc) · 5.49 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
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
# $550, 1200 ml of water, 540 ml of milk, 120 g of coffee beans, and 9 disposable cups.
class covfefe:
"""A class that contains parameters of coffee types"""
def __init__(self, money, water, milk, coffee, dcups):
self.money = money
self.water = water
self.milk = milk
self.coffee = coffee
self.dcups = dcups
class twogirls1cup:
"""A coffee machine class"""
# available coffee types
espresso = covfefe(4, 250, 0, 16, 1)
latte = covfefe(7, 350, 75, 20, 1)
cappuccino = covfefe(6, 200, 100, 12, 1)
def __init__(self, money, water, milk, coffee, dcups):
self.money = money
self.water = water
self.milk = milk
self.coffee = coffee
self.dcups = dcups
self.state = "select action"
print("Write action (buy, fill, take, remaining, exit):")
def setmainmenu(self):
self.state = "select action"
print("Write action (buy, fill, take, remaining, exit):")
def check(self, coffee_type):
if self.water - coffee_type.water < 0:
print("Sorry, not enough water!")
return False
if self.coffee - coffee_type.coffee < 0:
print("Sorry, not enough coffee beans!")
return False
if self.dcups - coffee_type.dcups < 0:
print("Sorry, not enough disposable cups!")
return False
return True
def make(self, coffee_type):
enough = self.check(coffee_type)
if not enough:
return
print("I have enough resources, making you a coffee!")
self.money += coffee_type.money
self.water -= coffee_type.water
self.milk -= coffee_type.milk
self.coffee -= coffee_type.coffee
self.dcups -= coffee_type.dcups
def take(self):
print("I gave you $" + str(self.money))
self.money = 0
def __str__(self):
a = "The coffee machine has:\n"
a += str(self.water) + " of water\n"
a += str(self.milk) + " of milk\n"
a += str(self.coffee) + " of coffee beans\n"
a += str(self.dcups) + " of disposable cups\n"
a += "$" + str(self.money) + " of money"
# a += str(self.money) + " of money"
return a
def buy(self, drink):
if drink == "back":
pass
# self.setmainmenu()
elif drink == "1":
self.make(self.espresso)
elif drink == "2":
self.make(self.latte)
elif drink == "3":
self.make(self.cappuccino)
else:
print("oxyel?")
def evaluate(self, userinput):
if self.state == "select action":
action = userinput
if action == "exit":
exit()
if action == "buy":
self.state = "select coffee"
print("What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu:\n")
elif action == "fill":
# self.fill()
self.state = "filling 1"
print("Write how many ml of water do you want to add:")
elif action == "take":
self.take()
self.setmainmenu()
elif action == "remaining":
print(self)
self.setmainmenu()
else:
print("Unknown action, uno-dos-quattro")
elif self.state == "select coffee":
drink = userinput
self.buy(drink)
self.setmainmenu()
elif self.state == "filling 1":
add_water = int(userinput)
self.water += add_water
self.state = "filling 2"
print("Write how many ml of milk do you want to add:")
elif self.state == "filling 2":
add_milk = int(userinput)
self.milk += add_milk
self.state = "filling 3"
print("Write how many grams of coffee beans do you want to add:")
elif self.state == "filling 3":
add_coffee = int(userinput)
self.coffee += add_coffee
self.state = "filling 4"
print("Write how many disposable cups of coffee do you want to add:")
elif self.state == "filling 4":
add_cups = int(userinput)
self.dcups += add_cups
self.setmainmenu()
coffee_machine = twogirls1cup(550, 400, 540, 120, 9)
while True:
action = input()
coffee_machine.evaluate(action)
# w = int(input("Write how many ml of water the coffee machine has:"))
# m = int(input("Write how many ml of milk the coffee machine has:"))
# c = int(input("Write how many grams of coffee beans the coffee machine has:"))
# cups = int(input("Write how many cups of coffee you will need:"))
# nw = w//200
# nm = m//50
# nc = c//15
# N = min(nw,nm,nc)
# if(cups<N):
# print("Yes, I can make that amount of coffee (and even " + str(N - cups) + " more than that)")
# elif(cups==N):
# print("Yes, I can make that amount of coffee")
# else:
# print("No, I can make only " + str(N) + " cups of coffee")
# cups = int(input("Write how many cups of coffee you will need:"))
# print("For 125 cups of coffee you will need:")
# print(str(cups * 200) + " ml of water")
# print(str(cups * 50) + " ml of milk")
# print(str(cups * 15) + " g of coffee beans")
# print("Starting to make a coffee")
# print("Grinding coffee beans")
# print("Boiling water")
# print("Mixing boiled water with crushed coffee beans")
# print("Pouring coffee into the cup")
# print("Pouring some milk into the cup")
# print("Coffee is ready!")