Basta Fazoolin' Issue

Hi,

I am getting the following error message -
Traceback (most recent call last):
File “script.py”, line 63, in
new_installment.available_menus(1200)
File “script.py”, line 54, in available_menus
if time >= menu.start_time and time < menu.end_time:
AttributeError: ‘str’ object has no attribute ‘start_time’

Not sure what I am missing here.

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

Please help.

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 "{name} menu available from {start_time} to {end_time}".format(name = self.name, start_time = self.start_time, end_time = self.end_time) def calculate_bill(self, puchased_items): total_price = 0 for purchased_item in puchased_items: if purchased_item in self.items: total_price += self.items[purchased_item] return ("Total Price: " + str(total_price)) 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, 2100) print(brunch_menu) print(brunch_menu.calculate_bill(['home fries','coffee'])) print(early_bird_menu.calculate_bill(['salumeria plate', 'mushroom ravioli (vegan)' ])) class Franchise: def __init__(self,address,menus): self.address = address self.menus = menus def __repr__(self): return ("The address is: " + self.address) def available_menus(self,time): self.time = 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 menus = ['brunch_menu', 'early_bird_menu', 'dinner_menu', 'kids_menu'] flagship_store = Franchise("1232 West End Road", menus) new_installment = Franchise("12 East Mulberry Street", menus) print(new_installment) new_installment.available_menus(1200)

Try removing line 51 and see what happens. time is not an instance variable, but a parameter.

note that menus will need to be a list of Menu objects, not a list of strings;
and you’ll need to create these Menu objects before putting them into this list.

1 Like

hi,

Thank you. It worked.

hi,

I am getting the correct output now. I had menus as strings instead of Menu objects. I have a doubt here. It works both with self.time and just time. How is it possible? I did not understand when you said time is not an instance variable, but a parameter. Can you please explain.

Thanks,
Varun

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 "{name} menu available from {start_time} to {end_time}".format(name = self.name, start_time = self.start_time, end_time = self.end_time) def calculate_bill(self, puchased_items): total_price = 0 for purchased_item in puchased_items: if purchased_item in self.items: total_price += self.items[purchased_item] return ("Total Price: " + str(total_price)) 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, 2100) print(brunch_menu) print(brunch_menu.calculate_bill(['home fries','coffee'])) print(early_bird_menu.calculate_bill(['salumeria plate', 'mushroom ravioli (vegan)' ])) class Franchise: def __init__(self,address,menus): self.address = address self.menus = menus def __repr__(self): return ("The address is: " + self.address) def available_menus(self,time): #self.time = 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 menus = [brunch_menu, early_bird_menu, dinner_menu, kids_menu] flagship_store = Franchise("1232 West End Road", menus) new_installment = Franchise("12 East Mulberry Street",menus) print(new_installment) print(new_installment.available_menus(1200))
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 "{name} menu available from {start_time} to {end_time}".format(name = self.name, start_time = self.start_time, end_time = self.end_time) def calculate_bill(self, puchased_items): total_price = 0 for purchased_item in puchased_items: if purchased_item in self.items: total_price += self.items[purchased_item] return ("Total Price: " + str(total_price)) 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, 2100) print(brunch_menu) print(brunch_menu.calculate_bill(['home fries','coffee'])) print(early_bird_menu.calculate_bill(['salumeria plate', 'mushroom ravioli (vegan)' ])) class Franchise: def __init__(self,address,menus): self.address = address self.menus = menus def __repr__(self): return ("The address is: " + self.address) def available_menus(self,time): self.time = time available_menus = [] for menu in self.menus: if self.time >= menu.start_time and self.time < menu.end_time: available_menus.append(menu) return available_menus menus = [brunch_menu, early_bird_menu, dinner_menu, kids_menu] flagship_store = Franchise("1232 West End Road", menus) new_installment = Franchise("12 East Mulberry Street",menus) print(new_installment) print(new_installment.available_menus(1200))

Good catch. You’re getting the hang of finding errors and omissions.

It works because you assigned time to self.time, a made up variable. time was passed to the method as a call argument. The instance variables of Franchise are, address and menus. Menu has name, items, start_time, and end_time. Instance variables are created at time of instantiation.

1 Like

Hi, Thank you Sir :slight_smile:

1 Like