Python 3 Basta Faloozin' Project, question 16 Error:

Probably a silly thing that is slipping my mind, but I have been encountering an error that I can’t seem to figure out on the Python 3 course, Basta Faloozin’ Project, question 16. I am even following along with the instruction video and can’t seem to figure out what I’m doing wrong. The issue is with the print(flagship_store.available_menus(1200))
command. Any help or input is appreciated!

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

Error: "Traceback (most recent call last):
File “script.py”, line 52, in
print(flagship_store.available_menus(str(1200)))
File “script.py”, line 44, in available_menus
if time >= menu.start_time and time <= menu.end_time:
AttributeError: ‘str’ object has no attribute ‘start_time’
"

Pasting Code here

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) + ' 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

brunch = Menu("Brunch", {'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}, 1100, 1600)

early_bird = Menu("Early Bird", {'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,}, 1500, 1800)

dinner = Menu("Dinner", {
  '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,
}, 1700, 2300)

kids = Menu("Kids", {
  'chicken nuggets': 6.50, 'fusilli with wild mushrooms': 12.00, 'apple juice': 3.00
}, 1100 , 2100)

print(dinner)
print(brunch.calculate_bill(['pancakes', 'home fries', 'coffee']))
print(early_bird.calculate_bill(['salumeria plate', 'mushroom ravioli (vegan)']))

menus = [brunch, early_bird, dinner, kids]

class Franchise:
  def __init__(self, address, menus):
    self.address = address
    self.menus = menus
  def __repr__(self):
    return "Our location is at " + self.address + " and has our " + self.menus + " menus!"

  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

flagship_store = Franchise("1232 West End Road", "Brunch, Early Bird, Dinner, and Kids")
new_installment = Franchise("12 East Mulberry Street", "Brunch, Early Bird, Dinner, and Kids")

print(flagship_store)
print(flagship_store.available_menus(1200))

Gist Link: Codecademy export · GitHub

Walkthrough Link: Python Project Walkthrough Basta Fazoolin' - YouTube

I think there may be a problem here:

flagship_store = Franchise(“1232 West End Road”, “Brunch, Early Bird, Dinner, and Kids”)

notice that “Brunch, Early Bird, Dinner, and Kids” is a string,
but it should probably be a list of menu objects (a list of instances of menu)

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

that way, when you do flagship_store.available_menus ,
it does menu.start_time for the menus in the list (inside the for loop)
instead of doing .start_time for the characters of a string

2 Likes

Thanks so much, that seemed to be the issue. I appreciate your help!