Basta Fazoolin'

Basta Fazoolin

i’m at the step 16 and got stuck on it

Summary
> 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 "{} Menu available at {}:00 to {}:00".format(self.name, self.start_time, self.end_time)
>   
>   def calculate_bill(self, purchased_items):
>     self.purchased_items=purchased_items
>     total_price=0
>     for x in purchased_items:
>       total_price += self.items[x]
>       print(x)
>     return total_price
>   
> class Franchise(Menu):
>   def __init__(self, address, menus):
>     self.address = address
>     self.menus = menus
>   
>   def __repr__(self):
>     return "The restaurant is located in: {}.".format(self.address)
>   
>   def available_menus(self, time):
>     self.time = time
>     return super().__init__(name, items, start_time, end_time)
> 
> print(Franchise.available_menus(12))

Traceback (most recent call last):
** File “script.py”, line 31, in **
** print(Franchise.available_menus(12))**
TypeError: available_menus() missing 1 required positional argument: 'time’

i get this error, got stuck on this for a day any help will be appreciated

Hi @mryasincengiz,

Instruction 14 asks us to create two Franchise instances.

Before calling the .available_menus() method, create at least one instance of Franchise, for example …

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

After that, it is best to use this syntax to call the method …

print(flagship_store.available_menus(12))

You could do it this way instead …

print(Franchise.available_menus(flagship_store, 12))

Either way, you need to specify an instance of Franchise.

when i call

print(flagship_store.available_menus(12))

i get None printed

from datetime import datetime, time
current_time=datetime.now()

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 "{} Menu available at {}:00 to {}:00".format(self.name, self.start_time, self.end_time)
  
  def calculate_bill(self, purchased_items):
    self.purchased_items=purchased_items
    total_price=0
    for x in purchased_items:
      total_price += self.items[x]
      print(x)
    return total_price
  
class Franchise(Menu):
  def __init__(self, address, menus):
    self.address = address
    self.menus = menus
  
  def __repr__(self):
    return "The restaurant is located in: {}.".format(self.address)
  
  def available_menus(self,time):
    self.time = time
    for i in self.menus:
      print(i)

flagship_store = Franchise("1232 West End Road",[brunch, early_bird, dinner, kids])
new_installment = Franchise("12 East Mulberry Street", [brunch, early_bird, dinner, kids])

print(flagship_store.available_menus(11))

Some code seems to be missing. For example, you need to create Menu instances before creating Franchise instances. It might be a good idea to check each of the instructions to make sure all necessary features are implemented as code.

An example of creating a Menu instance is …

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

You have Franchise as a subclass of Menu here …

class Franchise(Menu):

Restaurants offer menus, but restaurants are not kinds of menus. This would be better …

class Franchise:

Within your available_menus method, you are not checking the time intervals during which the Menu instances are available. Try something like this …

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

thank you so much for your help finally it works, i think i didn’t understand the concepts of the classes well enough i’m gonna go back and redo the exercises

1 Like

Let us know how it goes as you complete the project.

Let’s keep in mind that the available_menus method is designed to handle Menus in which the duration of availability is contained entirely within a single day. If we were to offer a "Night Owl" selection that started, let’s say, at 10:00 PM and ended at 2 AM the next day, we would need additional work to handle it. With a 24 hour clock, the starting time would be 22 while the ending time would be 2. Handling this is perhaps beyond the scope of this project, but implementing this feature could serve as extra practice for those who have completed it.

1 Like

How did you use menu.start_time?

How is menu an object of Menu?

Both of these are absolutely basic to the notion of classes, and you should understand them before attempting this exercise.

If they are not clear, I think that you should you carefully review each step of the Classes module before proceeding.

While doing so, be sure to return here to the forum with any questions on material you don’t understand. By the time you return to Basta Fazoolin’, you will find it to be much easier!

1 Like

I’m just confused how this instance variable from different class used here?
And we didn’t create any menu object (class instance from Menu) to use it over here?

When @appylpye showed this:

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

… it was as a method of the Franchise class, not the Menu class, and menus is an attribute of the Franchise class (see Steps 13 & 16), consisting of a list of Menu objects.

Each Menu object has a start_time and end_time attribute.

So, in the exercise, we have five menus, each a Menu object having its own items dictionary, start_time and end_time. They are arapas_menu, brunch, early_bird, dinner, and kids.

And, then when you decide to open a franchise, you must select which of those menus to offer. You put those menus into a list, and then initialize your franchise:

my_franchise = Franchise(my_address, my_menu_lst)

The __init__() method of Franchise sets self.address = my_address, and self.menus = my_menu_lst

… and now you are ready to run that available_menus() method! Just call

print(my_franchise.available_menus("8 AM"))

3 Likes

Thanks alot! Helped me now.

1 Like

I have a problem with available_menus.
When I try to do it this way I got TypeError: ‘>=’ not supported between instances of ‘int’ and ‘datetime.time’:

  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(time)
    return available_menus

And when I tried this I got :

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

I get this error: TypeError: ‘>=’ not supported between instances of ‘type’ and ‘datetime.time’

I tried casting int(menu.start_time) and end time but it is also not suported. Is there a way to do it with datetime? Any hint?

EDIT:

I tried changing datetime to int like this:

class Franchise:
  def __init__(self, address, menus):
    self.address = address
    self.menus = menus
  def __repr__(self):
        return "The address of this installment is " + str(self.address)
  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(time)
    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):
        return str(self.name) + " is being served from " + str(self.start_time) + " to " + str(self.end_time)
    
  def calculate_bill(self, purchased_items):
    price = 0
    for key, value in self.items.items():
      if key in purchased_items:
        price += value
    print(price)    
      
    

    
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
}, 11, 16)

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,
}, 15, 18)

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,
}, 17, 23)

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

menus = [brunch, early_bird, dinner, kids]
flagship_store  = Franchise("1232 West End Road", [brunch, early_bird, dinner, kids])
new_installment = Franchise("12 East Mulberry", [brunch, early_bird, dinner, kids])


print(flagship_store.available_menus(0))
print(flagship_store.available_menus(16))

My output looks like this:

[]
[16, 16, 16]

What the heck?!

Hello, @system2494758475.
The lists being printed come from where? Go back to there, and see how the list is put together. What are the values being appended to the list?
Hint: