Advertisement
Guest User

Untitled

a guest
Jun 14th, 2022
80
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MENU = {
  2.     "espresso": {
  3.         "ingredients": {
  4.             "water": 50,
  5.             "coffee": 18,
  6.         },
  7.         "cost": 1.5,
  8.     },
  9.     "latte": {
  10.         "ingredients": {
  11.             "water": 200,
  12.             "milk": 150,
  13.             "coffee": 24,
  14.         },
  15.         "cost": 2.5,
  16.     },
  17.     "cappuccino": {
  18.         "ingredients": {
  19.             "water": 250,
  20.             "milk": 100,
  21.             "coffee": 24,
  22.         },
  23.         "cost": 3.0,
  24.     }
  25. }
  26.  
  27. resources = {
  28.     "water": 300,
  29.     "milk": 200,
  30.     "coffee": 100,
  31.     "money": 0,
  32. }
  33.  
  34. COIN_VALUES = {
  35.     "quarters": 0.25,
  36.     "dimes": 0.1,
  37.     "nickles": 0.05,
  38.     "pennies": 0.01,
  39. }
  40.  
  41.  
  42. def inserted_coin_value() -> object:
  43.     """Asks the user for the coins and returns their total value"""
  44.     print("Please insert coins. ")
  45.     total = 0
  46.     for coin in COIN_VALUES:
  47.         how_many_coins = int(input(f"How many {coin}?: "))
  48.         total += how_many_coins * COIN_VALUES[coin]
  49.     return total
  50.  
  51.  
  52. def is_transaction_successful(total, user_coffee_choice):
  53.     """Checks whether the user can afford the product. True when can, False when can't. """
  54.     if MENU[user_coffee_choice]["cost"] <= total:
  55.         resources["money"] = resources["money"] + drink["cost"]
  56.         return True
  57.     else:
  58.         return False
  59.  
  60.  
  61. def are_resources_sufficient(drink):
  62.     """ Checks whether there is enough ingredients for each of the products and returns True when the order can be made, False when not."""
  63.     for ingredient in drink["ingredients"]:
  64.         if resources[ingredient] < (drink["ingredients"][ingredient]):
  65.             print(f"Sorry, there's not enough {ingredient}.")
  66.             return False
  67.         return True
  68.  
  69.  
  70. def print_report():
  71.     """Prints current report on resources"""
  72.     print(f"Water: {resources['water']}ml")
  73.     print(f"Milk: {resources['milk']}ml")
  74.     print(f"Coffee: {resources['coffee']}g")
  75.     print(f"Money: ${resources['money']}")
  76.  
  77.  
  78. def make_coffee():
  79.     """Removes amt of ingredients from resources{}. """
  80.     for ingredient in drink["ingredients"]:
  81.         resources[ingredient] = resources[ingredient] - drink["ingredients"][ingredient]
  82.  
  83.  
  84. is_on = True
  85.  
  86. while is_on:
  87.     user_coffee_choice = str(input("What would you like? espresso ($1.5)/latte ($2.5)/cappuccino ($3.0): "))
  88.     if user_coffee_choice == "report":
  89.         print_report()
  90.     elif user_coffee_choice == "off":
  91.         is_on = False
  92.     else:
  93.         drink = MENU[user_coffee_choice]
  94.         if are_resources_sufficient(drink):
  95.             total = inserted_coin_value()
  96.             if is_transaction_successful(total, user_coffee_choice):
  97.                 make_coffee()
  98.                 if total > drink["cost"]:
  99.                     change = round(total - drink["cost"], 2)
  100.                     print(f"Here's ${change} in change")
  101.                 print(f"Here's your {user_coffee_choice}. Enjoy!")
  102.             else:
  103.                 print("Sorry, that's not enough money. Money refunded.")
  104.  
Advertisement
RAW Paste Data Copied
Advertisement