Project Basta Fazoolin' stuck at task 16

Hi,
I’m doing the Basta Fazoolin project. Everything worked fine until task 16.

My code doesn’t return the correct list of the Menu objects that are available at a specific time.
I believe it has something to do with the way I defined the time_display method.

If someone can help me figure it out, I’d appreciate it.
Thanks

# Design software to handle operations for a chain of restaurants (basta_fazoolin.py)

# Define a class for the 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
    self.time_display()
    print(f'{self.name.title()}:')

# Define a method to format the menu's time display, 
# including AM/PM indication when necessary
  def time_display(self):
    start_suffix = 'am' if self.start_time < 12 else 'pm'
    end_suffix = 'am' if self.end_time < 12 else 'pm'
    start_time_12hr = self.start_time - 12 if self.start_time > 12 else self.start_time 
    end_time_12hr = self.end_time - 12 if self.end_time > 12 else self.end_time 
    self.start_suffix = start_suffix
    self.end_suffix = end_suffix
    self.start_time_12hr = start_time_12hr
    self.end_time_12hr = end_time_12hr  

# Define a method to calculate the total price of an order
  def calculate_bill(self, purchased_items):
    self.purchased_items = purchased_items
    total_price = sum(self.items[item] for item in purchased_items)
    return total_price

# Define a string representation method to describe the availability of the menus
  def __repr__(self):
    return (f'Menu available from '
            f'{self.start_time_12hr}{self.start_suffix} to '
            f'{self.end_time_12hr}{self.end_suffix}.')

# Create the brunch menu instance
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
    }, 
    11, 16
)

print(brunch,'\n')

# Create the early bird menu instance
early_bird = Menu(
    'early bird dinner', 
    {
        'salumeria plate': 8.00, 'pizza with quattro formaggi': 9.00, 
        'salad and breadsticks (serves 2, no refills)': 14.00, 'duck ragu': 17.50, 
        'mushroom ravioli (vegan)': 13.50, 'coffee': 1.50, 'espresso': 3.00
    }, 
    15, 18
)

print(early_bird,'\n')

# Create the dinner menu instance
dinner = Menu(
    'dinner', 
    {
        '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
    }, 
    17, 23
)

print(dinner,'\n')

# Create the kids menu instance
kids = Menu(
    'kids', 
    {
        'chicken nuggets': 6.50, 'fusilli with wild mushrooms': 12.00, 
        'apple juice': 3.00
    }, 
    11, 21
)

print(kids,'\n')

# Calculate bill for one brunch order
purchased_items = ['pancakes', 'home fries', 'coffee']
print(f'Bill No.1: ${brunch.calculate_bill(purchased_items)} '
      f'for {", ".join(purchased_items)}.\n')

# Calculate bill for one early_bird order
purchased_items = ['salumeria plate', 'mushroom ravioli (vegan)']
print(f'Bill No.2: ${early_bird.calculate_bill(purchased_items)} '
      f'for {', '.join(purchased_items)}.\n')

# Define a class for the opening of the franchise    
class Franchise:
  def __init__(self, address, menus):
    self.address = address
    self.menus = menus
  
  def available_menus(self, time):
    self.time = time
    available_menus = [menu.name for menu in self.menus 
                       if menu.start_time_12hr <= time <= menu.end_time_12hr]
    return available_menus

  def __repr__(self):
    return (f'{self.address}')

# Create the first franchise instance
flagship_store = Franchise('1232 West End Road', 
                           [brunch, early_bird, dinner, kids])

print(f'Flagship Store Address:\n{flagship_store}\n')

# Create the second franchise instance
new_installment = Franchise('12 East Mulberry Street', 
                            [brunch, early_bird, dinner, kids])

print(f'New Installment Address:\n{new_installment}\n')

# Print the available menus
time = 5
print(f'Available Menus at {time}: {', '.join(new_installment.available_menus(time)).title()}')


Did you check here?
Maybe there’s a potential solution to be found there first.

I did check, but either the solutions provided don’t apply to my case or I don’t fully understand what’s wrong which could very much be.

I think I’m confused as to how you defined the time_display method.

I also think there is an issue with how you defined the method for available menus. Specifically, here:

if menu.start_time_12hr <= time <= menu.end_time_12hr]
#perhaps missing an and operator in the conditional statement

Wouldn’t this work?

Summary
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

unfortunately, it doesn’t work. Nothing gets appended.
I believe the biggest issue is here:

 start_suffix = 'am' if self.start_time < 12 else 'pm'
    end_suffix = 'am' if self.end_time < 12 else 'pm'
    start_time_12hr = self.start_time - 12 if self.start_time > 12 else self.start_time 
    end_time_12hr = self.end_time - 12 if self.end_time > 12 else self.end_time 
    self.start_suffix = start_suffix
    self.end_suffix = end_suffix
    self.start_time_12hr = start_time_12hr
    self.end_time_12hr = end_time_12hr  

I agree. But why not just keep it as military time as I think it’s suggested in the lesson(?)

My menu class looks a bit different.

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

Also, the times that you passed in for the menus is based on military time (zeroes omitted).

See:
11, 16
15, 18,
17, 23
11, 23

I understand your point.
What I did was to have each time passed in as AM/PM format, hence the code below:

start_suffix = 'am' if self.start_time < 12 else 'pm'
end_suffix = 'am' if self.end_time < 12 else 'pm'
start_time_12hr = self.start_time - 12 if self.start_time > 12 else self.start_time 
end_time_12hr = self.end_time - 12 if self.end_time > 12 else self.end_time 

The ‘am’ suffix is added if the time is < 12. Then, since I passed times with zeroes omitted and based on military time as you said, I subtracted 12 from each time to get a correct AM/PM format. However, I believe that this is causing some trouble with the task 16.
If I can’t solve it, I’ll just change the time_display method.

I think of having found the solution:

 def available_menus(self, time):
    self.time = time
    available_menus = [menu.name for menu in self.menus if menu.start_time <= time <= menu.end_time]
    return available_menus
# Assuming the given time is in 24-hour format, convert it to 12-hour format
time = 23
if time <= 12:
  time_24hr = time + 12
elif time > 12:
  time_24hr = time - 12
else:
  time_24hr = time

print(
    f"Available Menus at {time_24hr}: {', '.join(new_installment.available_menus(time_24hr)).title()} \n")

By using this conditional, I correctly obtains the menus at the given AM/PM hours.