-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
146 lines (102 loc) · 3.12 KB
/
Copy pathmain.py
File metadata and controls
146 lines (102 loc) · 3.12 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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,
}
}
resources = {
"water": 300,
"milk": 200,
"coffee": 100,
}
def menu_info(which):
wtr = MENU[which]['ingredients']['water']
try:
mlk = MENU[which]['ingredients']['milk']
except KeyError:
mlk = 0
java = MENU[which]['ingredients']['coffee']
price = MENU[which]['cost']
return wtr, mlk, java, price
def check_resources(wtr,mlk,cfe):
if resources['water'] >= wtr:
if resources['milk'] >= mlk:
if resources['coffee'] >= cfe:
resources['water'] -= wtr
resources['milk'] -= mlk
resources['coffee'] -= cfe
return True
else:
print('Sorry, there is not enough coffee.')
return False
else:
print('Sorry, there is not enough milk.')
return False
else:
print('Sorry, there is not enough water.')
return False
def enough_money(price):
print('Please insert coins.')
quarters = 0.25 * float(input('How many quarters: '))
dimes = 0.10 * float(input('How many dimes: '))
nickels = 0.05 * float(input('How many nickels: '))
pennies = 0.01 * float(input('How many pennies: '))
user_money = quarters + dimes + nickels + pennies
if user_money >= float(price):
change = float(user_money) - float(price)
print(f'Here is ${change:.2f} in change.')
global money
money += price
return True
else:
print('Sorry that\'s not enough money. Money refunded.')
return False
money = 0
game_over = False
while not game_over:
choice = input('What would you like? (espresso/latte/cappuccino): ')
if choice == 'espresso':
water, milk, coffee, cost = menu_info(choice)
if enough_money(cost) and check_resources(water, milk, coffee):
print(f'Here is your {choice}. Enjoy☕!')
else:
continue
elif choice == 'latte':
water, milk, coffee, cost = menu_info(choice)
if enough_money(cost) and check_resources(water, milk, coffee):
print(f'Here is your {choice}. Enjoy☕!')
else:
continue
elif choice == 'cappuccino':
water, milk, coffee, cost = menu_info(choice)
if enough_money(cost) and check_resources(water, milk, coffee):
print(f'Here is your {choice}. Enjoy☕!')
else:
continue
elif choice == 'off':
print()
game_over = True
elif choice == 'report':
print(f"Water: {resources['water']}ml")
print(f"Milk: {resources['milk']}ml")
print(f"Coffee: {resources['coffee']}g")
print(f"Money: {money}")