|
| 1 | +import datetime |
| 2 | +Menu = { |
| 3 | + "latte": { |
| 4 | + "ingredients": { |
| 5 | + "water": 200, |
| 6 | + "milk": 150, |
| 7 | + "coffee": 24, |
| 8 | + }, |
| 9 | + "cost": 100, |
| 10 | + }, |
| 11 | + "espresso": { |
| 12 | + "ingredients": { |
| 13 | + "water": 50, |
| 14 | + "coffee": 18, |
| 15 | + }, |
| 16 | + "cost": 75, |
| 17 | + }, |
| 18 | + "cappuccino": { |
| 19 | + "ingredients": { |
| 20 | + "water": 250, |
| 21 | + "milk": 100, |
| 22 | + "coffee": 24, |
| 23 | + }, |
| 24 | + "cost": 100, |
| 25 | + }, |
| 26 | +} |
| 27 | + |
| 28 | +profit = 0 |
| 29 | +resources = { |
| 30 | + "water": 1000, |
| 31 | + "milk": 500, |
| 32 | + "coffee": 100, |
| 33 | +} |
| 34 | + |
| 35 | + |
| 36 | +def check_resources(order_ingredients): |
| 37 | + for item in order_ingredients: |
| 38 | + if order_ingredients[item] > resources[item]: |
| 39 | + print(f"Sorry there is not enough {item}") |
| 40 | + return False |
| 41 | + return True |
| 42 | + |
| 43 | + |
| 44 | +def process_coins(): |
| 45 | + print("Please insert coins.") |
| 46 | + total = 0 |
| 47 | + coins_five = int(input("How many 5rs coin?:")) |
| 48 | + coins_Ten = int(input("How many 10rs coin?:")) |
| 49 | + coins_Twenty = int(input("How many 20rs coin?:")) |
| 50 | + total = coins_five * 5 + coins_Ten * 10 + coins_Twenty * 20 |
| 51 | + return total |
| 52 | + |
| 53 | + |
| 54 | +def is_payment_successful(money_received, coffee_cost): |
| 55 | + if money_received >= coffee_cost: |
| 56 | + global profit |
| 57 | + profit += coffee_cost |
| 58 | + change = money_received - coffee_cost |
| 59 | + print(f"Here is your Rs{change} in change.") |
| 60 | + return True |
| 61 | + else: |
| 62 | + print("Sorry that's not enough money. Money refunded.") |
| 63 | + return False |
| 64 | + |
| 65 | + |
| 66 | +def make_coffee(coffee_name, coffee_ingredients): |
| 67 | + for item in coffee_ingredients: |
| 68 | + resources[item] -= coffee_ingredients[item] |
| 69 | + print(f"Here is your {coffee_name} ....Enjoy!!") |
| 70 | + |
| 71 | +def display_menu_and_date(): |
| 72 | + current_date = datetime.date.today() |
| 73 | + print(f"Welcome to the Coffee Machine!") |
| 74 | + print(f"Today's Date: {current_date}") |
| 75 | + print("\nMenu:") |
| 76 | + for coffee in Menu: |
| 77 | + cost = Menu[coffee]["cost"] |
| 78 | + print(f"{coffee.capitalize()} - Rs{cost}") |
| 79 | + print("\nType 'report' to see resource status.") |
| 80 | + print("Type 'off' to turn off the machine.") |
| 81 | + |
| 82 | + |
| 83 | +is_on = True |
| 84 | +while is_on: |
| 85 | + display_menu_and_date() |
| 86 | + choice = input( |
| 87 | + "What would you like to have? (latte/espresso/cappuccino): ") |
| 88 | + if choice == "off": |
| 89 | + is_on = False |
| 90 | + elif choice == "report": |
| 91 | + print(f"Water: {resources['water']}ml") |
| 92 | + print(f"Milk: {resources['milk']}ml") |
| 93 | + print(f"Coffee: {resources['coffee']}g") |
| 94 | + print(f"Money: Rs {profit}") |
| 95 | + else: |
| 96 | + coffee_type = Menu[ |
| 97 | + choice] # Retrieve the selected coffee type from the menu |
| 98 | + print(coffee_type) |
| 99 | + if check_resources(coffee_type['ingredients']): |
| 100 | + payment = process_coins() |
| 101 | + if is_payment_successful(payment, coffee_type['cost']): |
| 102 | + make_coffee(choice, coffee_type['ingredients']) |
0 commit comments