forked from rk199985/CoffeeMachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
87 lines (77 loc) · 3.41 KB
/
main.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
from data import menu, resources
# TODO 1: print report of available resources
def report():
"""prints a report of the available resources in machine"""
print(f"Available Resources:\n"
f"Water: {resources['water']} ml \n"
f"Milk: {resources['milk']} ml \n"
f"Coffee: {resources['coffee']} g")
# TODO 3 Check for resource availability of ingredients for the order
def resource_availability(order):
"""Returns "Yes" if ingredients are available, insufficient if not available"""
if order == 'espresso':
if resources["water"] > menu["espresso"]["ingredients"]["water"]:
if resources["coffee"] > menu["espresso"]["ingredients"]["coffee"]:
return "Yes"
else:
return "Insufficient Coffee"
else:
return "Insufficient Water"
if order == 'latte':
if resources["water"] > menu["latte"]["ingredients"]["water"]:
if resources["coffee"] > menu["latte"]["ingredients"]["coffee"]:
if resources["milk"] > menu["latte"]["ingredients"]["milk"]:
return "Yes"
else:
return "Insufficient Milk"
else:
return "Insufficient Coffee"
else:
return "Insufficient Water"
if order == 'cappuccino':
if resources["water"] > menu["cappuccino"]["ingredients"]["water"]:
if resources["coffee"] > menu["cappuccino"]["ingredients"]["coffee"]:
if resources["milk"] > menu["cappuccino"]["ingredients"]["milk"]:
return "Yes"
else:
return "Insufficient Milk"
else:
return "Insufficient Coffee"
else:
return "Insufficient Water"
# TODO 4 : Calculate money
def accounts(pennies, quarters, dimes, nickels, order):
"""Calculates inserted amount and returns balance amount if transaction is accepted or -1 rejected"""
inserted_amount = pennies * 0.01 + quarters * 0.25 + dimes * 0.1 + nickels * 0.05
bill = menu[order]["cost"]
if inserted_amount >= bill:
resources["money"] += bill
return round(inserted_amount - bill, 2)
else:
return -1
is_on = True
# TODO 2: Ask for user input from menu
while is_on:
order = input("What would you like to have espresso/latte/cappuccino?\n")
if order == 'report':
report()
else:
availability = resource_availability(order)
if availability == "Yes":
pennies = int(input("How many pennies?\n"))
nickels = int(input("How many nickels?\n"))
dimes = int(input("How many dimes?\n"))
quarters = int(input("How many quarters?\n"))
return_amount = accounts(pennies=pennies, nickels=nickels, dimes=dimes, quarters=quarters, order=order)
# TODO 5 Deliver Order and update resources
if return_amount == -1:
print("Sorry that is not enough money, Amount refunded")
else:
if order == "espresso":
resources["milk"] -= menu[order]["ingredients"]["milk"]
resources["water"] -= menu[order]["ingredients"]["water"]
resources["coffee"] -= menu[order]["ingredients"]["coffee"]
print(f"Here is your {order}, and change ${return_amount}")
else:
print("Sorry", availability)
is_on = False