PYTHON OBJECTS Basta Fazoolin'

can someone please please tell me what is wrong with my code, it keeps printing the empty block when i try to print available_menus method:

class Menu:
  def __init__(self, name, items, start_time, end_time):
    self.name = name
    self.items = items
    self.start_time = start_time
    self.end_time = end_time
    
  def __repr__(self):
    return f'''
    {self.name} menu
    on offer: {self.items}
    {self.name} menu available from {self.start_time} to {self.end_time}
    '''
  def calculate_bill(self, purchased_items):
    bill = 0
    for p in purchased_items:
      if p in self.items:
        bill += self.items[p]
    return ("you ate " + str(bill) + " dollars wow!")



class Franchise:
  def __init__(self, address, menus):
    self.address = address
    self.menus = menus
   
  def __repr__(self):
    return f'''
    address: {self.address}
    
    '''

  

  def available_menus(self, time):
    available_menus = []
    for menu in self.menus:
      if time >= menu.start_time and time <= menu.end_time:
        available_menus.append(menu)
     
    return available_menus
      

brunch = Menu("brunch", {
  '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
}, 1100, 1600)   

early_bird = Menu("early bird", {
  '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,
}, 1500, 1800)

dinner = Menu("dinner", {
  'crostini with eggplant caponata': 13.00, 'ceaser salad': 16.00, 'pizza with quattro formaggi': 11.00, 'duck ragu': 19.50, 'mushroom ravioli (vegan)': 13.50, 'coffee': 2.00, 'espresso': 3.00,
}, 1700, 2300)


kids = Menu("kids", {
  'chicken nuggets': 6.50, 'fusilli with wild mushrooms': 12.00, 'apple juice': 3.00
}, 1100, 2100)



customer_1 = brunch.calculate_bill(['pancakes', 'home fries', 'coffee'])



customer_2 = early_bird.calculate_bill(["salumeria plate", "mushroom ravioli (vegan)"])


  

menu = [brunch, early_bird, dinner, kids]

flagship_store = Franchise("1232 West End Road", menu)

new_installment = Franchise("12 East Mulberry Street", menu)




print(flagship_store.available_menus(12))


exercise link
https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-python-classes/projects/basta-fazoolin

Have a quick check of the values for various menu.start_time and menu.end_time attributes and then consider what value of time you are passing. If that doesn’t help, throw some print statements in the method to see what is being tested.

2 Likes

thanks man, the print(12) was supposed to be print(1200)

1 Like