-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPD15_Coffeemachine.py
122 lines (104 loc) · 4.02 KB
/
PD15_Coffeemachine.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
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
resources = {
"water_count": 300,
"milk_count": 200,
"coffee_count": 100,
"money_count": 0
}
def check(water_need, milk_need, coffee_need):
"""Takes 3 inputs and tells if the machine can prepare the given order"""
global resources
b = ""
need = []
if resources["water_count"] >= water_need and resources["milk_count"] >= milk_need and resources["coffee_count"] >= coffee_need:
process = True
else:
process = False
if resources["water_count"] < water_need:
need.append("water")
elif resources["milk_count"] < milk_need:
need.append("milk")
elif resources["coffee_count"] < coffee_need:
need.append("coffee")
for i in need:
b = b + "," + i
print(f"Sorry there is not enough {b}.")
return process
def coins():
"""Function to check if the user has paid enough, and how much change should be given to him."""
quarter = int(input("How many quarters?:"))
dimes = int(input("How many dimes?:"))
nickels = int(input("How many nickels?:"))
pennies = int(input("How many pennies?:"))
paid = (quarter * 0.25) + (dimes * 0.10) + (nickels * 0.05) + (pennies * 0.01)
return paid
def requirements_alter(money_need, water_need, milk_need, coffee_need):
"""Function to alter the resources dictionary, after a successful trade."""
resources["money_count"] = resources["money_count"] + money_need
resources["water_count"] = resources["water_count"] - water_need
resources["milk_count"] = resources["milk_count"] - milk_need
resources["coffee_count"] = resources["coffee_count"] - coffee_need
def machine(water_need, milk_need, coffee_need, money_need):
"""The main function that is the base of the coffee machine."""
global resources
process = check(water_need, milk_need, coffee_need)
if process is True:
print("Please insert coins.")
paid = coins()
if paid >= money_need:
print(f"Here is your change:{paid - money_need}")
requirements_alter(money_need, water_need, milk_need, coffee_need)
print("Here is your Expresso☕️")
else:
print("Sorry that's not enough money. Money refunded.")
def add():
global resources
milk_add = int(input("How much milk do you wish to add:"))
water_add = int(input("How much water do you wish to add:"))
coffee_add = int(input("How much coffee do you wish to add:"))
money_take = int(input("How much money do you wish to withdraw:"))
if money_take <= resources["money_count"]:
resources["milk_count"] = resources["milk_count"] + milk_add
resources["water_count"] = resources["water_count"] + water_add
resources["coffee_count"] = resources["coffee_count"] + coffee_add
resources["money_count"] = resources["money_count"] - money_take
else:
print("The machine does not have this much money.")
def expresso():
global resources
water_need = 50
milk_need = 0
coffee_need = 18
money_need = 1.5
machine(water_need, milk_need, coffee_need, money_need)
def latte():
global resources
water_need = 200
milk_need = 150
coffee_need = 24
money_need = 2.5
machine(water_need, milk_need, coffee_need, money_need)
def cappuccino():
global resources
water_need = 250
milk_need = 100
coffee_need = 24
money_need = 3
machine(water_need, milk_need, coffee_need, money_need)
a = True
while a is True:
decision = input("What do you like(espresso/latte/cappuccino):").lower()
if decision == "off":
a = False
elif decision == "report":
print("Water:", resources["water_count"], "\nMilk:", resources["milk_count"], "\nCoffee:",
resources["coffee_count"], "\nMoney:", resources["money_count"])
elif decision == "expresso":
expresso()
elif decision == "latte":
latte()
elif decision == "cappuccino":
cappuccino()
elif decision == "add":
add()
else:
print("Decision not clear")