-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoffeMachineSimple
79 lines (67 loc) · 1.96 KB
/
CoffeMachineSimple
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
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,
}
def pay():
userquestion = input("What would you like? Espresso, latte or cappuccino? ").lower()
if userquestion == "report":
for key, value in resources.items():
print(f"{key.capitalize()}: {value}")
pay()
elif userquestion == "off":
exit()
else:
drink = MENU[userquestion]
if itemResources(drink["ingredients"]):
if checkMoneyResource(drink["cost"]):
print(f"Enjoy in your {userquestion}")
for ingredient, amount in drink["ingredients"].items():
resources[ingredient] -= amount
pay()
def checkMoneyResource(cost):
print("Please insert your coins")
quarters = int(input("How many quarters do you have? "))
dimes = int(input("How many dimes do you have? "))
nickles = int(input("How many nickles do you have? "))
pennies = int(input("How many pennies do you have? "))
total = quarters * 0.25 + dimes * 0.1 + nickles * 0.05 + pennies * 0.01
print(f"You insert a {round(total, 2)}$")
if total >= cost:
refund = total - cost
print(f"Money refunded {round(refund, 2)}$")
return total
else:
print("That is not enough money. Money refunded")
def itemResources(ingredients):
for item in ingredients:
if ingredients[item] >= resources[item]:
print(f"Sorry, that is not enough {item}.")
return False
return True
pay()