Basta Fazoolin' Error

Hey Guys!

I have been having an attribute error show up (in relation to Basta Fazoolin’ Python 3 project) after I save my code after attempting step #16. I’ve read the code over again a couple of times, but no luck so far. I am also new to coding and Python 3, so still trying to learn how it operates. So, I was wondering if anyone else could help me figure out what the issues are. Thank you in advance!

My code:

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 self.name + ' menu available from ' + str(self.start_time) + ' - ' + str(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_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)
print(brunch_menu.name)

print(brunch_menu.calculate_bill(['pancakes', 'home fries', 'coffee']))

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)

print(early_bird_menu.calculate_bill(['salumeria plate', 'mushroom ravioli (vegan)']))

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 = Menu('Dinner', dinner_items, 1700, 2300)

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 Mulberry Store', menus)

print(flagship_store.available_menus(1200))

The error:
Traceback (most recent call last):
File “script.py”, line 63, in
print(flagship_store.available_menus(1200))
AttributeError: ‘Franchise’ object has no attribute ‘available_menus’

Link: https://www.codecademy.com/courses/learn-python-3/projects/basta-fazoolin

Haven’t gone through the whole code, but just a quick look shows issues with indentation. Unlike some other languages, indentation is very important in Python.

Have a look at the indentation of      def __repr__(self):

It should have the same indentation as the __init__ and available_menus methods of the Franchise class.

Also, the indentation of      return available_menus       needs to be fixed.

1 Like

Hello, mtrtmk,

Yeah, the error did result from those indentations issues that you pointed out in your initial message. The code ran errorless after fixing those issues and saving what had been written. Thank you for the information about correct indentations being very important for the Python coding language.

1 Like