JkSoftware

Day 16 - menu.py

Nov 25th, 2021
601
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class MenuItem:
  2.     """Models each Menu Item."""
  3.     def __init__(self, name, water, milk, coffee, cost):
  4.         self.name = name
  5.         self.cost = cost
  6.         self.ingredients = {
  7.             "water": water,
  8.             "milk": milk,
  9.             "coffee": coffee
  10.         }
  11.  
  12.  
  13. class Menu:
  14.     """Models the Menu with drinks."""
  15.     def __init__(self):
  16.         self.menu = [
  17.             MenuItem(name="latte", water=200, milk=150, coffee=24, cost=2.5),
  18.             MenuItem(name="espresso", water=50, milk=0, coffee=18, cost=1.5),
  19.             MenuItem(name="cappuccino", water=250, milk=50, coffee=24, cost=3),
  20.         ]
  21.  
  22.     def get_items(self):
  23.         """Returns all the names of the available menu items"""
  24.         options = ""
  25.         for item in self.menu:
  26.             options += f"{item.name}/"
  27.         return options
  28.  
  29.     def find_drink(self, order_name):
  30.         """Searches the menu for a particular drink by name. Returns that item if it exists, otherwise returns None"""
  31.         for item in self.menu:
  32.             if item.name == order_name:
  33.                 return item
  34.         print("Sorry that item is not available.")
RAW Paste Data