Basta Fazoolin Project: how do I get all available menus at a given time?

Hi,
This is my first time posting on this forum. Am taking the python course.

Here is a link to an exercise I am working on: https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-python-classes/projects/basta-fazoolin

I was attempting to answer Question 16 which is as follows : Let’s tell our customers what they can order! Give Franchise an .available_menus() method that takes in a time parameter and returns a list of the Menu objects that are available at that time.

My code is included below. I do not get the right menus returned as available for a given time of day. For example, for 1700 hrs I get no menus . Is there an error in my code below? I am still trying to figure out what the error is…

class Franchise:
  def __init__(self, address, menus):
    self.address = address
    self.menus = menus
  
  def __repr__(self):
    return 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

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 "{} menu available from {} to {}".format(self.name, self.start_time, self.end_time)

  def calculate_bill(self, purchased_items):
    bill = 0
    for purchased_item in purchased_items:
      if purchased_item in self.items: 
        bill +=self.items[purchased_item]
    return bill

#brunch menu
brunch_items = {'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}

brunch_menu = Menu('Brunch', brunch_items, 1100, 1600)
#early bird menu
early_bird_items = {'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,}

early_bird_menu = Menu('Early Bird', early_bird_items, 1500, 1800)

#dinner menu
dinner_items = {'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,}

dinner_menu = Menu ('Dinner',dinner_items , 1700, 2300)

#kids menu
kids_items = {'chicken nuggets': 6.50, 'fusilli with wild mushrooms': 12.00, 'apple juice': 3.00}
kids_menu = Menu('Kids', kids_items, 1100, 2100)

menus = [brunch_menu, early_bird_menu, dinner_menu, kids_menu]

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

new_installment = Franchise("12 East Muberry Street", menus )

print (flagship_store.available_menus(1700))



1 Like

Hi @taimurkhanafridi, welcome to the forums. Have a close look at the section where you check all of the menus. What order are those statements exectued in, is it what you intended? If you’re not sure, check with some print statements or similar.

Hi,
Thanks for your response. Are you referring to the above section?

Yes, wherever you are checking each of the menus for their relevant attributes.

For posterity: I was able to resolve the matter by un-indenting “return available_menus”. New format as above. Thanks

2 Likes