इस कोड में, हमें एक मेनू और संसाधनों की जरूरत होती है ताकि हम विभिन्न प्रकार के कॉफ़ी ड्रिंक्स बना सकें। संसाधनों की उपलब्धता और पैसे की गणना की जांच की जाती है और तब तक कॉफ़ी बनाई जाती है जब तक कि प्रत्येक उपकरण की पर्याप्तता नहीं होती है।
youtube video https://youtube.com/shorts/i4DrE8-J2Nw?feature=share
MENU = { "espresso": { "ingredients": { "water": 50, "coffee": 18, }, "cost": 1.5, }, "latte": { "ingredients": { "water": 200, "milk": 150, "coffee": 24, }, "cost": 2.5, }, "cappuccino": { "ingredients": { "water": 250, "milk": 100, "coffee": 24, }, "cost": 3.0, } } profit = 0 resources = { "water": 300, "milk": 200, "coffee": 100, } def is_resource_sufficient(order_ingredients): for item in order_ingredients: if order_ingredients[item] >= resources[item]: print(f"Sorry there is not enough {item}.") return False return True def process_coins(): """Returns the total calculation from coins insered""" print("Please insert coins.") total = int(input("How many qaurters? : "))* 0.255 total += int(input("how many dimes? : ")) * 0.1 total += int(input("how many nickles? :")) * 0.05 return total def is_transaction_successful(money_reccived, drink_cost): if money_reccived >= drink_cost: change = round(money_reccived - drink_cost, 2) print(f"Here is {change} in change.") global profit profit += drink_cost return True else: print("Sorry that's not enough money./n Money refunded.") return False def make_coffee(drink_name, order_ingredients): """Deduct the requied ingredients from the resourses.""" for item in order_ingredients: resources[item] -= order_ingredients[item] print(f"Here is your {drink_name}") is_need = True while is_need: choice = input("What would you like? (espresso/latte/cappuccino):\n") if choice == "off": is_need = False print("machine shutting down") elif choice == "report": print(f"Water: {resources['water']}ml") print(f"Milk: {resources['milk']}ml") print(f"Coffee: {resources['coffee']}g") print(f"Money: ${profit}") else: drink = MENU[choice] if is_resource_sufficient(drink["ingredients"]): payment = process_coins() if is_transaction_successful(payment, drink['cost']): make_coffee(choice, drink["ingredients"])
No comments:
Post a Comment