100 Days of Code: The Complete Python Pro Bootcamp for 2022 - Day 15 (Coffee Machine Order)
fromartimportlogoprint(logo)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=0resources={"water":300,"milk":200,"coffee":100,}defis_resource_sufficient(order_ingredients):"""Returns True when order can be made, False if ingredients are insufficient."""foriteminorder_ingredients:iforder_ingredients[item]>resources[item]:print(f"Sorry there is not enough {item}.")returnFalsereturnTruedefprocess_coins():"""Returns the total calculated from coins inserted."""print("Please insert coins.")total=int(input("how many quarters?: "))*0.25total+=int(input("how many dimes?: "))*0.1total+=int(input("how many nickles?: "))*0.05total+=int(input("how many pennies?: "))*0.01returntotaldefis_transaction_successful(money_received,drink_cost):"""Return True when the payment is accepted, or False if money is insufficient."""ifmoney_received>=drink_cost:change=round(money_received-drink_cost,2)print(f"Here is ${change} in change.")globalprofitprofit+=drink_costreturnTrueelse:print("Sorry that's not enough money. Money refunded.")returnFalsedefmake_coffee(drink_name,order_ingredients):"""Deduct the required ingredients from the resources."""foriteminorder_ingredients:resources[item]-=order_ingredients[item]print(f"Here is your {drink_name} ☕️. Enjoy!")is_on=Truewhileis_on:choice=input("What would you like? (espresso/latte/cappuccino): ")ifchoice=="off":is_on=Falseelifchoice=="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]ifis_resource_sufficient(drink["ingredients"]):payment=process_coins()ifis_transaction_successful(payment,drink["cost"]):make_coffee(choice,drink["ingredients"])
Top comments (0)
Subscribe
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)