Advertisement
Guest User

cafetería

a guest
Jun 15th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.72 KB | None | 0 0
  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. }
  32.  
  33. profit = 0
  34.  
  35. def payment():
  36.    
  37.     print("\nPlease insert coins.\n")
  38.     print(coffee + " price: $" + str(MENU[coffee]["cost"]))
  39.    
  40.     quarters = int(input("How many quarters?: ")) * 0.25
  41.    
  42.     # dimes = int(input("How many dimes?: ")) * 0.1
  43.     # nickles = int(input("How many nickles?: ")) * 0.05
  44.     # pennies = int(input("How many pennies?: ")) * 0.01
  45.     # total = quarters + dimes + nickles + pennies
  46.    
  47.     total = quarters
  48.    
  49.     if coffee == "espresso":
  50.         refund = total - MENU["espresso"]["cost"]
  51.  
  52.     elif coffee == "latte":
  53.         refund = total - MENU["latte"]["cost"]
  54.        
  55.     elif coffee == "cappuccino":
  56.         refund = total - MENU["cappuccino"]["cost"]
  57.    
  58.     if refund < 0:
  59.         missing = refund * -1
  60.         print(f"You need ${missing} more for your ${coffee}.")
  61.      
  62.     else:
  63.         print(f"Your ${coffee} in on the way!")
  64.        
  65. def resources_subtract():
  66.     if coffee == "espresso":
  67.         resources["water"] -= 50
  68.         resources["coffee"] -= 18
  69.        
  70.     elif coffee == "latte":
  71.         resources["water"] -= 200
  72.         resources["coffee"] -= 24
  73.         resources["milk"] -= 150
  74.        
  75.        
  76.        
  77.     elif coffee == "cappuccino":
  78.         resources["water"] -= 250
  79.         resources["coffee"] -= 24
  80.         resources["milk"] -= 100
  81.  
  82.  
  83. def coffee_selection():
  84.        
  85.     if coffee == "report":
  86.         print("water:", resources["water"])
  87.         print("coffee:", resources["coffee"])
  88.         print("milk:", resources["milk"])
  89.         print(f"The totalal profit is: ${profit}")
  90.     elif coffee in MENU:
  91.         payment()
  92.     else:
  93.         print("error 404 coffee not found")
  94.  
  95. def resources_check():
  96.     enough_items = True
  97.     missing_item = ""
  98.    
  99.     if coffee == "espresso":
  100.         if resources["water"] < 49:
  101.             missing_item = "water"
  102.            
  103.         elif resources["coffee"] < 17:
  104.             missing_item = "coffe"
  105.            
  106.            
  107.     elif coffee == "latte":
  108.         if resources["water"] < 199:
  109.             missing_item = "water"
  110.            
  111.         elif resources["coffee"] < 23:
  112.             missing_item = "coffe"
  113.            
  114.         elif resources["milk"] < 149:
  115.             missing_item = "milk"
  116.            
  117.     elif coffee == "cappuccino":
  118.         if resources["water"] < 249:
  119.             missing_item = "water"
  120.    
  121.         elif resources["coffee"] < 23:
  122.             missing_item = "coffe"
  123.            
  124.         elif resources["milk"] < 99:
  125.             missing_item = "milk"
  126.    
  127.     if missing_item != "":
  128.         enough_items = False
  129.         print("Sorry not enough " + missing_item)
  130.        
  131.     return enough_items
  132.    
  133.  
  134. is_on = True
  135.  
  136. while is_on:
  137.     coffee = input("\nWhat would you like? (espresso/latte/cappuccino):\n").lower()
  138.    
  139.     enough_resources = resources_check()
  140.    
  141.     if enough_resources:
  142.    
  143.         if coffee == "off":
  144.             is_on = False
  145.         elif coffee == "espresso":
  146.             profit += 1.5
  147.         elif coffee == "latte":
  148.             profit += 2.5
  149.         elif coffee == "cappuccino":
  150.             profit += 3
  151.    
  152.  
  153.         coffee_selection()
  154.         resources_subtract()
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement