|
| 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) |
0 commit comments