Basta Fazoolin' - Step 16 - AttributeError: 'tuple' object has no attribute 'end_time'

class Franchise:

  def __init__(self, address, menus):

    self.address = address

    self.menus = menus

  def __repr__(self):

    return self.address

  def available_menus(self, time):

    menus_now = []

    for menu in self.menus:

      if time <= menu.end_time and time > menu.start_time:

        menus_now.append(menu)

    return menus_now

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 '%s. %s:00 to %s:00' %(self.name, self.start_time, self.end_time)

  def calculate_bill(self, purchased_items):

    total = 0

    for item in purchased_items:

      total += self.items.get(item)

    return total

    



kids = ('Kids', kids_items, 11, 21)

flagship_store = Franchise("1232 West End Road", [brunch, early_bird, dinner, kids])

new_installment = Franchise("12 East Mulberry Street", [brunch, early_bird, dinner, kids])

eat = flagship_store.available_menus(5)

Error message

Traceback (most recent call last):
  File "script.py", line 60, in <module>
    eat = flagship_store.available_menus(5)
  File "script.py", line 12, in available_menus
    if time <= menu.end_time and time > menu.start_time:
AttributeError: 'tuple' object has no attribute 'end_time'

Anyone have any idea what I’m missing here? I’m going crazy.

Hi! Welcome to the forums :slight_smile:

It looks like you haven’t initialized/defined your menus.

Something like this:

kids = ('Kids', kids_items, 11, 21)

is really a tuple of a string, some undefined kids_item object, and two integers.

To define the kids menu you could try something like:

kids = Menu('Kids', kids_items, 11, 21)

(although you still have the issue of not having defined kids_items). But now it is a object of class Menu instead of a tuple.

3 Likes

Sorry I ddin’t include some of my code in order to make it smaller but your answer is correct!!

Thank you.

I had
kids = ('Kids', kids_items, 11, 21)
but I should have put
kids = Menu('Kids', kids_items, 11, 21)

You’re the best!!

1 Like