Basta Fazoolin' project, loop stops when first match is found

Howdy all,

Here is the link to the project:

In this project I should make a loop so thta all the restaurant menus available at a certain hour would be displayed to the client.

However, when the loop finds the first True in the IF code it stops…

Please help this newby :slight_smile:

class Franchise:

def __init__(self, address, menus, name): = name
    self.address = address = menus

def __repr__(self):
    return 'Welcome to {name}, our address is {add}'.format(, add=self.address)

def available_menus(self, time):
    i = 0
    while i < len(
        if time >=[i].start_time and time <=[i].end_time:
            return[i], i
        i += 1

That’ because the ‘return’ stop the execution of the function. So if you need to return more elements of a list, is better to create a new empty list to contain the elements to return, and then return that list.

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

That’s how I managed this situation

Thank you! Was going crazy about this :slight_smile:

1 Like