Basta Fazoolin' challenge

URL is provided below
https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-python-classes/projects/basta-fazoolin

What I wonder is this. In Francise class and available_menu method, the line "if time >= menu.start_time and time <= menu.end_time: " is written.
Here “menu.start_time” is used and “menu” seems to be an object of “Menu class”. I wonder how that could be?

class Francise:
  def __init__(self, address, menus):
    self.address = address
    self.menus = menus
  def __repr__(self):
    return self.address
  def available.menu(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):
    if self == brunch:
      return "brunch menu available from 11am to 4pm"
    if self == early_bird:
      return "early_bird dinner menu available from 3pm to 6pm"
    if self == dinner:
      return "dinner menu available from 5pm to 11pm"  
    if self == kids:
      return "kids menu available from 11am to 9pm "     
  def calculate_bill(self, purchased_items):
    total_price = 0
    for element in purchased_items:
      total_price += self.items[element]
    return total_price

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

1 Like

Hi!

2 things:

  1. The method available.menu() should be called available_menu() with an underscore, the period will throw a syntax error.

  2. when you write the for loop: the basic structure is for i in item:. i is not previously named before, it represents what each item will be in the iterations.
    If i say for animal in park:, for each different iteration of the loop, animal will be whatever is in that iterable object park (for example dog, bird).

In summary, for menu in self.menus will cycle through item in your self.menus variable, so on the first loop menu will be brunch menu, then on the 2nd early-bird, 3rd dinner (etc, whatever order they’re in depending on how you code them). The point is you can name it for bicycles in self.menus and it will still run, the issue is just that the name doesn’t make sense and you won’t be able to understand your code later (in more complicated scenarios).
(if you want more info on for loops: i suggest [https://www.youtube.com/watch?v=6iF8Xb7Z3wQ]

1 Like