Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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,
- }
- }
- resources = {
- "water": 300,
- "milk": 200,
- "coffee": 100,
- "money": 0,
- }
- COIN_VALUES = {
- "quarters": 0.25,
- "dimes": 0.1,
- "nickles": 0.05,
- "pennies": 0.01,
- }
- def inserted_coin_value() -> object:
- """Asks the user for the coins and returns their total value"""
- print("Please insert coins. ")
- total = 0
- for coin in COIN_VALUES:
- how_many_coins = int(input(f"How many {coin}?: "))
- total += how_many_coins * COIN_VALUES[coin]
- return total
- def is_transaction_successful(total, user_coffee_choice):
- """Checks whether the user can afford the product. True when can, False when can't. """
- if MENU[user_coffee_choice]["cost"] <= total:
- resources["money"] = resources["money"] + drink["cost"]
- return True
- else:
- return False
- def are_resources_sufficient(drink):
- """ Checks whether there is enough ingredients for each of the products and returns True when the order can be made, False when not."""
- for ingredient in drink["ingredients"]:
- if resources[ingredient] < (drink["ingredients"][ingredient]):
- print(f"Sorry, there's not enough {ingredient}.")
- return False
- return True
- def print_report():
- """Prints current report on resources"""
- print(f"Water: {resources['water']}ml")
- print(f"Milk: {resources['milk']}ml")
- print(f"Coffee: {resources['coffee']}g")
- print(f"Money: ${resources['money']}")
- def make_coffee():
- """Removes amt of ingredients from resources{}. """
- for ingredient in drink["ingredients"]:
- resources[ingredient] = resources[ingredient] - drink["ingredients"][ingredient]
- is_on = True
- while is_on:
- user_coffee_choice = str(input("What would you like? espresso ($1.5)/latte ($2.5)/cappuccino ($3.0): "))
- if user_coffee_choice == "report":
- print_report()
- elif user_coffee_choice == "off":
- is_on = False
- else:
- drink = MENU[user_coffee_choice]
- if are_resources_sufficient(drink):
- total = inserted_coin_value()
- if is_transaction_successful(total, user_coffee_choice):
- make_coffee()
- if total > drink["cost"]:
- change = round(total - drink["cost"], 2)
- print(f"Here's ${change} in change")
- print(f"Here's your {user_coffee_choice}. Enjoy!")
- else:
- print("Sorry, that's not enough money. Money refunded.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement