-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (74 loc) · 2.4 KB
/
main.py
File metadata and controls
82 lines (74 loc) · 2.4 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
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,
"money": 0,
}
def start():
prompt = input("What would you like? (espresso/latte/cappuccino): ").lower()
global should_continue
if prompt == 'off':
print("Turning off...")
return False
elif prompt == 'report':
print(f"""Water: {resources['water']}ml
Milk: {resources['milk']}ml
Coffee: {resources['coffee']}g
Money: ${resources['money']}""")
return True
elif prompt in MENU: # Check if the user's choice is valid
chosen_coffee = MENU[prompt]
for ingredient, amount in chosen_coffee['ingredients'].items():
if resources.get(ingredient, 0) < amount:
print("Sorry there is not enough ingredients")
return True
print(f"The price of the coffee you want is: {chosen_coffee['cost']}$") # Use 'cost' instead of 'price'
print("Please insert coins")
quarters = int(input("How many quarters?: "))
dimes = int(input("How many dimes?: "))
nickles = int(input("How many nickles?: "))
pennies = int(input("How many pennies?: "))
total_money_inserted = quarters * 0.25 + dimes * 0.10 + nickles * 0.05 + pennies * 0.01
print(f"Total money inserted: ${round(total_money_inserted, 2)}")
if total_money_inserted < chosen_coffee['cost']:
print("Sorry that's not enough money. Money refunded")
return True
change = total_money_inserted - chosen_coffee['cost']
resources['money'] += chosen_coffee['cost']
if change > 0:
print(f"Here's ${round(change, 2)} in change")
for ingredient, amount in chosen_coffee['ingredients'].items():
resources[ingredient] -= amount
print(f"Here's your {prompt}☕. Enjoy!")
return True
else:
print("Invalid choice.")
return True
should_continue = True
while should_continue:
should_continue = start()