-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoffeMachine.py
More file actions
117 lines (84 loc) · 2.81 KB
/
Copy pathCoffeMachine.py
File metadata and controls
117 lines (84 loc) · 2.81 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
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,
}
}
profit = 0
resources = {
"water": 300,
"milk": 200,
"coffee": 100,
}
def is_rosource_sufficient(order_ingredients):
is_enough = True
for item in order_ingredients:
if order_ingredients[item]>=resources[item]:
print(f"Sorry there is not enough water{item}")
is_enough = False
return is_enough
def is_transaction_succeful(money_receive, drink_cost):
# Note: I was not getting it hightlight, because they were not define
""" This will return Ture when the payment is accepted, ,or False when if money is not sufficient."""
if money_receive >= drink_cost:
# To reache the profit from a global scope
change = round(money_receive - drink_cost, 2)
print(f"Here is your change {change}")
global profit
profit += drink_cost
return True
else:
print("Sorry that's not enough money. Money refunded.")
return False
def process_coin():
"""
Return True when the order can be make or False when not ingredient no suffiecient
"""
print("Insert coins")
total = int(input("How many quarters\n")) * 0.25
total += int(input("How many dimes\n")) * 0.10
total += int(input("How many nickles\n")) * 0.05
total += int(input("How many pennies\n")) * 0.01
return total
def make_coffe(drink_name, order_ingredients):
""" Deduct the required ingredients from the resources"""
for item in order_ingredients:
resources[item] -= order_ingredients[item]
print(f"Here is your {drink_name}☕")
run_machine = True
while run_machine:
"""Return the total calculated from coins inserted"""
choice = input("What would you like? (espresso/latte/cappuccino)").lower()
if choice == "off":
run_machine = False
elif choice == "report":
print(f"Water: {resources['water']} ml")
print(f"Milk: {resources['milk']}50ml")
print(f"Coffee:{resources['coffee']}76g")
print(f"Money:{profit}")
else:
drink = MENU[choice]
#print(drink)
if is_rosource_sufficient(drink["ingredients"]):
payment = process_coin()
if is_transaction_succeful(payment, drink["cost"]):
make_coffe(choice, drink["ingredients"])