-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (49 loc) · 1.75 KB
/
Copy pathmain.py
File metadata and controls
58 lines (49 loc) · 1.75 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
import data
profit = 0.0
resources = {
"water": 300,
"milk": 200,
"bean": 100
}
def coffee_machine_status(resource: dict, income: float):
for item in resource:
print(f"{item.title()}: {resource[item]}")
print(f"Money: ${income:.2f}")
def is_resource_sufficient(beverage: str, resource: dict, menu: dict):
for item in resource:
if resource[item] < menu[beverage]['ingredients'][item]:
print(f"Sorry, that's not enough {item}")
return False
return True
def get_money():
total = int(input("How many quarters?: ")) * 0.25
total += int(input("How many dimes?: ")) * 0.10
total += int(input("How many nickels?: ")) * 0.05
total += int(input("How many pennies?: ")) * 0.01
return total
while True:
coffee = input("What would you like to drink?☕ 'espresso' or 'latte' or 'cappuccino': ")
# hide command for owner
if coffee == "report":
coffee_machine_status(resources, profit)
continue
if coffee == "off":
break
# process coffee
if is_resource_sufficient(coffee, resources, data.menu):
menu_cost = data.menu[coffee]['cost']
print("Please insert coins")
insert_money = get_money()
if menu_cost > insert_money:
print("Sorry,that's not enough money. Money refunded")
continue
else:
if menu_cost < insert_money:
print(f"Here is ${insert_money - menu_cost:.2f} dollar in change")
print(f"Here is your {coffee}. Enjoy!")
# Deduct the ingredients amount from resources machine has
for item in resources:
resources[item] -= data.menu[coffee]['ingredients'][item]
profit += menu_cost
else:
continue