menu.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. class Menu:
  12. """Models the Menu with drinks."""
  13. def __init__(self):
  14. self.menu = [
  15. MenuItem(name="latte", water=200, milk=150, coffee=24, cost=2.5),
  16. MenuItem(name="espresso", water=50, milk=0, coffee=18, cost=1.5),
  17. MenuItem(name="cappuccino", water=250, milk=50, coffee=24, cost=3),
  18. ]
  19. def get_items(self, resources):
  20. """Returns all the names of the available menu items"""
  21. options = ""
  22. for item in self.menu:
  23. is_sufficient_resources = True
  24. for ingredient in item.ingredients:
  25. if item.ingredients[ingredient] > resources[ingredient]:
  26. is_sufficient_resources = False
  27. if is_sufficient_resources:
  28. options += f"{item.name}/"
  29. if options == "":
  30. return None
  31. else:
  32. return options[0:-1]
  33. def find_drink(self, order_name):
  34. """Searches the menu for a particular drink by name. Returns that item if it exists, otherwise returns None"""
  35. for item in self.menu:
  36. if item.name == order_name:
  37. return item
  38. print("Sorry that item is not available.")