
Read Time:1 Minute, 38 Second
RESOURCES = { "water": [300, "ml"], "milk": [200, "ml"], "coffee": [100, "g"], "money": [0, "$"], } MENU = { "espresso": { "ingredients": { "water": 50, "coffee": 18, }, "cost": 1.5, }, "latte": { "ingredients": { "water": 200, "coffee": 18, "milk": 150, }, "cost": 2.5, }, "cappuccino": { "ingredients": { "water": 250, "coffee": 100, "milk": 24, }, "cost": 2.5, }, } machine_state = "ON" def off(): global machine_state print("Turning off....") machine_state = "OFF" def transaction(money, coffee): if money < MENU[coffee]["cost"]: print("sorry that's not enough money.Money refunded. ") return False elif money > MENU[coffee]["cost"]: print(f'Here is ${round(money-MENU[coffee]["cost"],2)} in change') return True def make_coffee(coffee): global RESOURCES if not check_resources(coffee): return entered_money = coin_input() if not transaction(entered_money, coffee): return RESOURCES["money"][0] += MENU[coffee]["cost"] for ingredients in MENU[coffee]["ingredients"]: RESOURCES[ingredients][0] -= MENU[coffee]["ingredients"][ingredients] print(f"Here is your {coffee} Enjoy!") def report(): for ingredients in RESOURCES: print(f"{ingredients} : {RESOURCES[ingredients][0]}{RESOURCES[ingredients][1]}") def menu(): for things in MENU: print(f'{things} : {MENU[things]["cost"]}$') def refill(): global RESOURCES RESOURCES["water"][0] = 300 RESOURCES["milk"][0] = 200 RESOURCES["coffee"][0] = 100 def helpme(): print("you can use this commands") for commands in Function_list: print(f"-> {commands}") def check_resources(coffee): for ingredients in MENU[coffee]["ingredients"]: if RESOURCES[ingredients][0] < MENU[coffee]["ingredients"][ingredients]: print(f"sorry there is not enough {ingredients}") return False return True def coin_input(): print("Please insert coins") pennies = 0 pennies += int(input("quarters: ")) * 0.25 pennies += int(input("dimes: ")) * 0.1 pennies += int(input("nickles: ")) * 0.05 pennies += int(input("pennies: ")) * 0.01 return pennies Function_list = { "off": off, "report": report, "menu": menu, "refill": refill, "?": helpme, "help": helpme, } while machine_state == "ON": command = input("what would you like? ").lower() if command in list(Function_list.keys()): Function_list[command]() elif command in list(MENU.keys()): make_coffee(command) else: print("Wrong key pressed") print(" Enter ? for help")
Average Rating