Skip to content

Commit ac9bdcd

Browse files
committed
add coffe machine program and data
1 parent 62fc7a6 commit ac9bdcd

File tree

3 files changed

+111
-16
lines changed

3 files changed

+111
-16
lines changed

CoffeeMachine/data.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
MENU = {
2+
"espresso": {
3+
"ingredients": {
4+
"water": 50,
5+
"coffee": 18,
6+
},
7+
"cost": 1.5,
8+
},
9+
"latte": {
10+
"ingredients": {
11+
"water": 200,
12+
"milk": 150,
13+
"coffee": 24,
14+
},
15+
"cost": 2.5,
16+
},
17+
"cappuccino": {
18+
"ingredients": {
19+
"water": 250,
20+
"milk": 100,
21+
"coffee": 24,
22+
},
23+
"cost": 3.0,
24+
}
25+
}
26+
27+
28+
resources = {
29+
"water": 300,
30+
"milk": 200,
31+
"coffee": 100
32+
}
33+

CoffeeMachine/main.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from data import MENU, resources
2+
3+
4+
def turn_off() -> None:
5+
print("Turning off Coffee Machine")
6+
7+
8+
def check_option(user_input: str, resources_machine: dict, money: float) -> None:
9+
if user_input == "off":
10+
turn_off()
11+
elif user_input == "report":
12+
print_report(resources_machine, money)
13+
run_machine(resources_machine, money)
14+
elif user_input == "espresso" or user_input == "latte" or user_input == "cappuccino":
15+
make_coffee(resources_machine, user_input, money)
16+
17+
18+
def print_report(resources_machine: dict, money: float) -> None:
19+
print(
20+
f'Water: {resources_machine["water"]}ml'
21+
f'\nMilk: {resources_machine["milk"]}ml'
22+
f'\nCoffee: {resources_machine["coffee"]}g'
23+
f'\nMoney: ${money}'
24+
)
25+
26+
27+
def check_resources(resources_machine: dict, coffee: str) -> list:
28+
29+
enough_resources = []
30+
for ingredient in MENU[coffee]["ingredients"]:
31+
if resources_machine[ingredient] < MENU[coffee]["ingredients"][ingredient]:
32+
enough_resources.append(ingredient)
33+
34+
return enough_resources
35+
36+
37+
def process_coins(coffee: str) -> int:
38+
print("Please, insert coins.")
39+
quarters = float(input("hoy many quarters?: "))
40+
dimes = float(input("how many dimes?: "))
41+
nickles = float(input("how many nickles?: "))
42+
pennies = float(input("how many pennies?: "))
43+
44+
total = quarters * 0.25 + dimes * 0.10 + nickles * 0.05 + pennies * 0.01
45+
total = total - MENU[coffee]["cost"]
46+
47+
return total
48+
49+
50+
def check_transaction(resources_machine: dict, coffee: str) -> dict:
51+
for ingredient in MENU[coffee]["ingredients"]:
52+
resources_machine[ingredient] = resources_machine[ingredient] - MENU[coffee]["ingredients"][ingredient]
53+
54+
return resources_machine
55+
56+
57+
def make_coffee(resources_machine: dict, coffee: str, money: float):
58+
enough_resources = check_resources(resources_machine, coffee)
59+
if len(enough_resources) == 0:
60+
total_money = process_coins(coffee)
61+
if total_money > 0:
62+
money += MENU[coffee]["cost"]
63+
resources_machine = check_transaction(resources_machine, coffee)
64+
65+
66+
print(f"Here is your {coffee}☕. Enjoy!")
67+
run_machine(resources_machine, money)
68+
else:
69+
lack_resources = ', '.join(enough_resources)
70+
print(f"Sorry, the next resources are not enough: {lack_resources}")
71+
72+
73+
def run_machine(resources_machine: dict, money: float):
74+
user_input = input("What would you like? (espresso/latte/cappuccino) ")
75+
check_option(user_input, resources_machine, money)
76+
77+
78+
run_machine(resources, 0)

main.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)