Basta Foozlin step 16

Hello, I have so far been stuck on step 16 for a while now and I don’t know why my code refuses to work the way that I want it to. If I were to use an “or” for my comparison it would work as it should in theory. The problem is when I put “and” as the operator which returns an empty list. I have looked at the video on this step quite a few times already. Is it possible if I could get a little help on this?
Thanks

import datetime 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 self.name + " menu will be available from " + self.start_time.strftime('%I:%M%p') + " to " + self.end_time.strftime('%I:%M%p') def calculate_bill(self, purchased_items): total = 0 for item in purchased_items: total += self.items[item] return total 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("Brunch", brunch_items, datetime.time(11), datetime.time(16)) 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("Early Bird", early_bird_items, datetime.time(15), datetime.time(18)) dinner_items = {'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} dinner = Menu("Dinner", dinner_items, datetime.time(17), datetime.time(23)) kids_items = {'chicken nuggets': 6.50, 'fusilli with wild mushrooms': 12.00, 'apple juice': 3.00} kids = Menu("Kids", kids_items, datetime.time(11), datetime.time(21)) #print(brunch) #print(brunch.calculate_bill(['pancakes', 'home fries', 'coffee'])) #print(early_bird.calculate_bill(['salumeria plate', 'mushroom ravioli (vegan)'])) 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_menu = [] for menu in self.menus: if time >= int(menu.start_time.strftime('%I')) and time <= int(menu.end_time.strftime('%I')): available_menu.append(menu) return available_menu standard_menus = [brunch, early_bird, dinner, kids] flagship_store = Franchise("1232 West End Road", standard_menus) new_installment = Franchise("12 East Mulberry Street", standard_menus) print(new_installment.available_menus(12))

Try printing the values used in your comparisons. I don’t think they are what you think they are.

Hint

Try:

    for menu in self.menus:
# Add the following print statement:
      print(f"time: {time} start: {int(menu.start_time.strftime('%I'))} end:  {int(menu.end_time.strftime('%I'))}")
      if time >= int(menu.start_time.strftime('%I')) and time <= int(menu.end_time.strftime('%I')):
        available_menu.append(menu)

Output:

time: 12 start: 11 end: 4
time: 12 start: 3 end: 6
time: 12 start: 5 end: 11
time: 12 start: 11 end: 9

Look at the values printed. Your if statement is fine, but the values need to be correct for the code to behave as expected.

3 Likes

Thank-you very much for your response. I forgot I was comparing 12 hour values which messed up the program.

1 Like