Basta Fazoolin Error on step 9-10

Hello! I am currently working on the Basta Fazoolin’ Exercise https://www.codecademy.com/courses/learn-python-3/projects/basta-fazoolin
and i am getting an error whenever i try to use the calculate_bill method (in my code, i am using the method on the brunch menu):

Traceback (most recent call last):
File “script.py”, line 16, in
print(brunch_menu.calculate_bill([‘pancakes’,‘home fries’, ‘coffee’]))
NameError: name ‘brunch_menu’ is not defined

I have looked over my code and i can not seem to find where the issue could be, as i also checked and compared it to the project walkthrough. We seem to have all the same code. This could very well be a simple mistake that i am missing, but any outsider advice would be appreciated. This is my code:

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 str(self.name) + " is available from " + str(self.start_time) + " to " + 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

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

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_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_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_items= {

    'chicken nuggets': 6.50, 'fusilli with wild mushrooms': 12.00, 'apple juice': 3.00

}

kids_menu=Menu("Kids", kids_items, 1100, 1500)

print(kids_menu)

Apologies if any of this is formatted incorrectly. I am very new to these forums. Thanks in advance for any kind of advice!

Hi there, and welcome to the forums!

Not sure if you’re getting other errors, but the error code indicates that this line is what is flagging the error, and specifically it says brunch_menu is not defined. If we look at the code, we can see that this line is called before brunch_menu has been defined, therefore the code cannot find that object when you call it. You need to either move the object declaration up or move the print statement down to below the declaration!

thank you so much! this makes a ton of sense, and i think it just was not something i fully understood before this. this clears everything up perfectly.