-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathcoffee_machine.py
More file actions
132 lines (128 loc) · 3.52 KB
/
coffee_machine.py
File metadata and controls
132 lines (128 loc) · 3.52 KB
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
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,
}
}
profit = 0
resources = {
"water": 300,
"milk": 200,
"coffee": 100,
}
end_of_task=True
while end_of_task:
def update_resources(cofee):
if (cofee == 'espresso'):
resources["water"]-=50
resources["coffee"]-=18
elif (cofee == 'latte'):
resources["water"]-=200
resources["milk"]-=150
resources["coffee"]-=24
elif (cofee == 'cappuccino'):
resources["water"]-=250
resources["milk"]-=100
resources["coffee"]-=24
def check_resources(cofee):
if cofee == 'espresso':
if resources["water"]<50:
print("Insufficient water")
return 0
elif resources["coffee"]<18:
print("Insufficient coffee")
return 0
elif cofee == 'latte':
if resources['water']<200:
print("Insufficient water")
return 0
elif resources["milk"]<150:
print("Insufficient milk")
return 0
elif resources["coffee"]<24:
print("Insufficient coffee")
return 0
elif cofee == 'cappuccino':
if resources["water"]<250:
print("Insufficient water")
return 0
elif resources["milk"]<100:
print("Insufficient milk")
return 0
elif resources["coffee"]<24:
print("Insufficient coffee")
return 0
def report():
for key in resources:
print(f"{key}: {resources[key]}ml")
print(f"Money: ${profit}")
choice=input("What would you like? (espresso/latte/cappuccino): ")
coffee(choice)
def coin():
print("please insert coins.")
quarter=int(input("how many quarters?: "))
dimes=int(input("how many dimes?: "))
nickles=int(input("how many nickles?: "))
pennies=int(input("how many pennies?: "))
coin=0.25*quarter+0.10*dimes+0.05*nickles+0.01*pennies
return coin
def coffee(choice):
global profit
# choice=input("What would you like? (espresso/latte/cappuccino): ")
if choice == 'report':
report()
else :
if (choice == 'espresso'):
check=check_resources(choice)
if check == 0:
end_of_task=False
if check!=0:
value=coin()
change=round(value-1.5,2)
profit+=1.5
print(f"Here is ${change} in change")
print("Here is your espresso. Enjoy!")
update_resources(choice)
elif (choice == 'latte'):
check=check_resources(choice)
if check == 0:
end_of_task=False
if check!=0:
value=coin()
change=round(value-2.5,2)
profit+=2.5
print(f"Here is ${change} in change")
print("Here is your latte. Enjoy!")
update_resources(choice)
elif (choice == 'cappuccino'):
check=check_resources(choice)
if check == 0:
end_of_task=False
if check!=0:
value=coin()
change=round(value-3.0,2)
profit+=3.0
print(f"Here is ${change} in change")
print("Here is your cappuccino. Enjoy!")
update_resources(choice)
choose=input("What would you like? (espresso/latte/cappuccino): ")
coffee(choose)