-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoffee_machine.py
90 lines (81 loc) · 2.77 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
class CoffeeMachine:
def __init__(self):
self.state = "ready"
self.water = 400
self.milk = 540
self.beans = 120
self.cups = 9
self.cash = 550
def user_input(self, push):
if self.state == "ready":
if push == "buy":
self.buy()
elif push == "fill":
self.fill()
elif push == "take":
self.take()
elif push == "remaining":
self.remaining()
def buy(self):
coffee_type = input("What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu:")
if coffee_type == "1":
req_water = 250
req_milk = 0
req_beans = 16
price = 4
elif coffee_type == "2":
req_water = 350
req_milk = 75
req_beans = 20
price = 7
elif coffee_type == "3":
req_water = 200
req_milk = 100
req_beans = 12
price = 6
else:
return
if self.water - req_water < 0:
print("Sorry, not enough water!")
return
if self.milk - req_milk < 0:
print("Sorry, not enough milk!")
return
if self.beans - req_beans < 0:
print("Sorry, not enough coffee beans!")
return
if self.cups - 1 < 0:
print("Sorry, not enough disposable cups!")
return
print("I have enough resources, making you a coffee!")
self.water -= req_water
self.milk -= req_milk
self.beans -= req_beans
self.cups -= 1
self.cash += price
def fill(self):
water = int(input("Write how many ml of water do you want to add:"))
milk = int(input("Write how many ml of milk do you want to add:"))
beans = int(input("Write how many grams of coffee beans do you want to add:"))
cups = int(input("Write how many disposable cups do you want to add:"))
self.water += water
self.milk += milk
self.beans += beans
self.cups += cups
def take(self):
print("I gave you ${}".format(self.cash))
self.cash = 0
def remaining(self):
print("The coffee machine has:")
print("{} of water".format(self.water))
print("{} of milk".format(self.milk))
print("{} of coffee beans".format(self.beans))
print("{} of disposable cups".format(self.cups))
print("{} of money".format(self.cash))
def main():
machine = CoffeeMachine()
action = input("Write action (buy, fill, take, remaining, exit):")
while action != "exit":
machine.user_input(action)
action = input("Write action (buy, fill, take, remaining, exit):")
main()