-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoffee_machine.py
86 lines (65 loc) · 3.74 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
#import modules
from machine_data import resources, menu, coins
machine_on = True
customer_money = 0
cash = 0
#prompt user by asking what would they like(espresso, latte, cappuccino), don't forget to run the loop so that it asks every time until the machine is turned off
while machine_on:
user_input = input("What would you like?(latte,cappuccino,espresso)\n").lower()
#turn off the machine by entering off to the prompt
if user_input == "off":
print("Machine is turned off")
machine_on = False
#print report
elif user_input == "report":
print(f"Water: {resources['water']}ml\nMilk: {resources['milk']}ml\nCoffee: {resources['coffee']}g\nMoney: ${cash}")
elif user_input == "espresso" or user_input == "latte" or user_input == "cappuccino":
quarters = int(input("How many quarters? "))
dimes = int(input("How many dimes? "))
nickels = int(input("How many nickels? "))
pennies = int(input("How many pennies? "))
#process coins
customer_money = quarters * coins["quarters"] + dimes * coins["dimes"] + nickels * coins["nickels"] + pennies * coins["pennies"]
else:
print("\n"*40)
print("Invalid input")
#check if the resources are sufficient or not
if user_input == "espresso":
if resources["water"] < menu["espresso"]["water"] or resources["coffee"] < menu["espresso"]["coffee"] or resources["milk"] < menu["espresso"]["milk"]:
print("Sorry resources is not enough to make espresso\nThe amount will be refunded")
elif customer_money < menu["espresso"]["cost"]:
print("Sorry the amount is not enough\nThe amount will be refunded")
else:
resources["water"] -= menu["espresso"]["water"]
resources["milk"] -= menu["espresso"]["milk"]
resources["coffee"] -= menu["espresso"]["coffee"]
left_amount = customer_money - menu["espresso"]["cost"]
cash += customer_money - left_amount
print("Enjoy your espresso☕")
print(f"Here is the change: ${left_amount}")
if user_input == "latte":
if resources["water"] < menu["latte"]["water"] or resources["coffee"] < menu["latte"]["coffee"] or resources["milk"] < menu["latte"]["milk"]:
print("Sorry resources is not enough to make latte\nThe amount will be refunded")
elif customer_money < menu["latte"]["cost"]:
print("Sorry the amount is not enough\nThe amount will be refunded")
else:
resources["water"] -= menu["latte"]["water"]
resources["milk"] -= menu["latte"]["milk"]
resources["coffee"] -= menu["latte"]["coffee"]
left_amount = customer_money - menu["latte"]["cost"]
cash += customer_money - left_amount
print("Enjoy your latte☕")
print(f"Here is the change: ${left_amount}")
if user_input == "cappuccino":
if resources["water"] < menu["cappuccino"]["water"] or resources["coffee"] < menu["cappuccino"]["coffee"] or resources["milk"] < menu["cappuccino"]["milk"]:
print("Sorry resources is not enough to make cappuccino\nThe amount will be refunded")
elif customer_money < menu["cappuccino"]["cost"]:
print("Sorry the amount is not enough\nThe amount will be refunded")
else:
resources["water"] -= menu["cappuccino"]["water"]
resources["milk"] -= menu["cappuccino"]["milk"]
resources["coffee"] -= menu["cappuccino"]["coffee"]
left_amount = customer_money - menu["cappuccino"]["cost"]
cash += customer_money - left_amount
print("Enjoy your cappuccino☕")
print(f"Here is the change: ${left_amount}")