Basta Fazoolin' Project

Hello,

I am working on the Basta Fazoolin Project and I have the following error:

Traceback (most recent call last):
File “script.py”, line 34, in
Early_bird_menu.calculate_bill([‘salumeria plate’])
AttributeError: ‘Menu’ object has no attribute ‘calculate_bill’

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

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 __rep__(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: bil += self.items[purchaded_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) 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) Early_bird_menu.calculate_bill(['salumeria plate']) 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, 2100)

I’m not sure exactly why but your code is rendering in a very odd way when I look at it. Assuming I’ve copied at least part of it right I’d suggest double-checking your indentation. To be part of the class any following statements should be indented (at least once). Once you drop the indentation you’re back in the global level script/module.

Couple of other things, it looks like there’s a return inside a loop which might exit earlier than you expect. Looks like a typo in the repr dunder method too, it’s __repr__.

Any reason why my list comprehension for question 16 didn’t work?

def available_menus(self, time):
     return [menu.name if menu.start_time <= time <= menu.end_time for menu in self.menus]

Also, does it make any difference if you keep all the class definitions at the top of the page as opposed to defining them as you go along the tasks?

I think the if stuff has to be at the end.

For example:

ls = [1, 2, 3, 4, 5, 6]
r = [num for num in ls if 3 <= num <= 5]
print(r)
2 Likes

Thank you

What about the classes? Do you happen to know the answer for that question too?

I don’t think the order is particularly important; all the classes don’t have to be at the top …
as long as you define each thing before you use it.

1 Like