Basta Fazoolin'


#1

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


#2

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.


#3

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

#4

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

#5

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


#6

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.