-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoffee_Machine.py
96 lines (75 loc) · 2.56 KB
/
Coffee_Machine.py
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
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
is_on = True
def is_resource_sufficient(order_ingredients):
"""This function calculates if the machine has the resources to make the coffee."""
for item in order_ingredients:
if order_ingredients[item] >= resources[item]:
print(f"Sorry, there's not enough {item}.")
return False
else:
resources[item] -= order_ingredients[item]
return True
while is_on == True:
request = input("What would you like? (espresso/latte/cappuccino): ").lower()
if request == "off":
print("Powering off.")
is_on = False
elif request == "report":
print(f"Water: {resources['water']}ml")
print(f"Milk: {resources['milk']}ml")
print(f"Coffee: {resources['coffee']}g")
print(f"Money: ${money}")
elif request in MENU:
drink = MENU[request]
if is_resource_sufficient(drink["ingredients"]):
print("Please insert coins.")
quarters = int(input("How many quarters? "))
dimes = int(input("How many dimes? "))
nickels = int(input("How many nickels? "))
pennies = int(input("How many pennies? "))
initial_coins = (quarters * 0.25) + (dimes * 0.1) + (nickels * 0.05) + (pennies * 0.01)
total_coins = round(initial_coins, 2)
if total_coins >= drink["cost"]:
money += total_coins
if total_coins > drink["cost"]:
change = total_coins - drink["cost"]
if change >= money:
print("Insufficient change in machine. Please contact the manager for assistance.")
else:
print(f"Here is your change: {change}")
money -= change
print("Enjoy your coffee.")
else:
print("Insufficient coins. Money refunded.")
else:
print(f"Invalid input. Please try again.")