Advertisement
lengthy_preamble

bas_faz

Jul 16th, 2022
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 KB | None | 0 0
  1. class Franchise:
  2.   def __init__(self, address, menus):
  3.     self.address = address
  4.     self.menus = menus
  5.  
  6.   def __repr__(self):
  7.     return f"We are located at {self.address}"
  8.  
  9.   def available_menus(self, time):
  10.     available_menus = []
  11.     for menu in self.menus:
  12.       if time >= menu.start_time and time <= menu.end_time:
  13.         available_menus.append(menu)
  14.     return available_menus
  15.  
  16.  
  17. class Menu:
  18.   def __init__(self, name, items, start_time, end_time):
  19.     self.name = name
  20.     self.items = items
  21.     self.start_time = start_time
  22.     self.end_time = end_time
  23.  
  24.   def __repr__(self):
  25.     return f"{self.name} menu available from {self.start_time} - {self.end_time}"
  26.  
  27.   def calculate_bill(self, purchased_items):
  28.     bill = 0
  29.     for purchased_item in purchased_items:
  30.       if purchased_item in self.items:
  31.         bill += self.items[purchased_item]
  32.     return bill
  33.  
  34.  
  35.  
  36.    
  37.  
  38. brunch_items = {
  39.   'pancakes': 7.50, 'waffles': 9.00, 'burger': 11.00, 'home fries': 4.50, 'coffee': 1.50, 'espresso': 3.00, 'tea': 1.00, 'mimosa': 10.50, 'orange juice': 3.50
  40. }
  41.  
  42. brunch_menu = Menu('Brunch', brunch_items, 1100, 1600)
  43.  
  44. early_bird_items = {
  45.   'salumeria plate': 8.00, 'salad and breadsticks (serves 2, no refills)': 14.00, 'pizza with quattro formaggi': 9.00, 'duck ragu': 17.50, 'mushroom ravioli (vegan)': 13.50, 'coffee': 1.50, 'espresso': 3.00,
  46. }
  47.  
  48. early_bird_menu = Menu('Early Bird', early_bird_items, 1500, 1800)
  49.  
  50. dinner_items = {
  51.   'crostini with eggplant caponata': 13.00, 'caesar salad': 16.00, 'pizza with quattro formaggi': 11.00, 'duck ragu': 19.50, 'mushroom ravioli (vegan)': 13.50, 'coffee': 2.00, 'espresso': 3.00,
  52. }
  53.  
  54. dinner_menu = Menu('Dinner', dinner_items, 1700, 2300)
  55.  
  56. kids_items = {
  57.   'chicken nuggets': 6.50, 'fusilli with wild mushrooms': 12.00, 'apple juice': 3.00
  58. }
  59.  
  60. kids_menu = Menu('Kids', kids_items, 1100, 2100)
  61.  
  62. menus = [brunch_menu, early_bird_menu, dinner_menu, kids_menu]
  63.  
  64. flagship_store = Franchise('1232 West End Road', Menu)
  65. new_installment = Franchise('12 East Mulberry Street', Menu)
  66.  
  67. # print(flagship_store)
  68. print(flagship_store.available_menus(1200))
  69. # print(brunch_menu.calculate_bill(['pancakes', 'home fries', 'coffee']))
  70. # print(early_bird_menu.calculate_bill(['salumeria plate', 'mushroom ravioli (vegan)']))
  71. # print(kids_menu)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement