-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaquina_cafe.py
More file actions
114 lines (98 loc) · 3.24 KB
/
maquina_cafe.py
File metadata and controls
114 lines (98 loc) · 3.24 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
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,
}
}
storage = {"ingredients": {
"water": 2000,
"milk": 1000,
"coffee": 500,
}
}
cashier = 0
def verify_ingredients(opcao):
valida = True
for item in MENU[opcao]["ingredients"]:
if MENU[opcao]["ingredients"][item] > storage["ingredients"][item]:
valida = False
if valida == False:
print(opcao, 'not available... please chose another option.')
return valida
def prepare_coffee(opcao):
print('Preparing your', opcao, '... please wait')
for item in MENU[opcao]["ingredients"]:
storage["ingredients"][item] -= MENU[opcao]["ingredients"][item]
print('Your', opcao, 'is ready, please take it in the tray!')
def extract():
for item in storage["ingredients"]:
print(item, ':', storage["ingredients"][item])
print('Total in the Cashier: US$', cashier)
def charge(opcao):
moedas = []
valor_pago = 0.0
retorno = False
moedas.append(input("How many Quarters?: "))
moedas.append(input("How many dimes?: "))
moedas.append(input("How many nickels?: "))
moedas.append(input("How many pennies?: "))
for i in range(0,len(moedas)):
if i == 0:
valor_pago += float(moedas[i]) * 0.25
elif i == 1:
valor_pago += float(moedas[i]) * 0.10
elif i == 2:
valor_pago += float(moedas[i]) * 0.05
else:
valor_pago += float(moedas[i]) * 0.01
if valor_pago > 0.0:
if valor_pago > MENU[opcao]['cost']:
troco = valor_pago - float(MENU[opcao]['cost'])
print('Thank you! You paid US$', valor_pago, ', your change is US$:', troco)
retorno = True
elif valor_pago < MENU[opcao]['cost']:
print('The coins were not sufficient, we are returning US$:', valor_pago)
retorno = False
else:
retorno = True
else:
print('You need to add some coins...')
if retorno:
global cashier
cashier += MENU[opcao]['cost']
return retorno
# ativando a máquina
liga = input('Would you like a coffee? Y / N :').upper()
# se ligou vamos à escolha do usuário:
while liga == 'Y':
if liga == 'Y':
selecionado = input('What caffee would you like? (espresso/latte/cappuccino):').upper()
if selecionado == 'OFF':
liga = 'N'
elif selecionado == 'EXTRACT':
extract()
elif selecionado != 'ESPRESSO' and selecionado != 'LATTE' and selecionado != 'CAPPUCCINO':
print('Invalid option...')
else:
if verify_ingredients(selecionado):
if charge(selecionado):
prepare_coffee(selecionado)