Basta Fazoolin'

No problem!

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 (f"this is the {self.name} menu. It is available from {self.start_time} to {self.end_time}.") 
  def calculate_bill(self, purchased_items):
    amount=0
    for items in purchased_items:
      amount+=self.items[items]
    return(f"Your total, pretax, is ${amount}")

  

class Franchise:
  def __init__(self, address, menus):
    self.address=address
    self.menus=menus

  def __repr__(self):
    return "the address of that franchise is {address}".format(address=self.address)
  
  def available_menus(self, time):
    menus_list=[]
    for menu in self.menus:
      if time >=menu.start_time and time <=menu.end_time:
        menus_list.append(menu)
    return menus_list

class Business:
  def __init__(self, name, franchises):
    self.name = name
    self.franchises = franchises


brunch_it = {'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
}
brunch = Menu("Brunch", brunch_it, 1100, 1600)
early_it = {
  '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,
}
early_bird = Menu("Early-Bird", early_it, 1500, 1800)

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

kids_it = {
  'chicken nuggets': 6.50, 'fusilli with wild mushrooms': 12.00, 'apple juice': 3.00
}
kids=Menu("Kids", kids_it, 1100, 2100)
arepas_it = {
  'arepa pabellon': 7.00, 'pernil arepa': 8.50, 'guayanes arepa': 8.00, 'jamon arepa': 7.50
}
arepas=Menu("Take a' Arepa", arepas_it, 1000, 2000)

menus=[brunch, early_bird, dinner, kids]  



flagship_store = Franchise("1232 West End Road", menus)
new_installment = Franchise("12 East Mulberry Street", menus)
basta_biz= Business("Basta Fazoolin' with my Heart", [flagship_store, new_installment])
arepas_place = Franchise("189 Fitzgerald Avenue", [arepas])

arepa = Business("Take a' Arepa", [arepas_place]) 


Well, I guess the origins of your original error will remain a mystery. I see nothing in your code that even when rearranged would have thrown your initial error.

2 Likes

Well, though we’ll never know for sure what raised the original error, since the original code evidently didn’t make it to the first post, let’s try to learn something from it. What might raise a TypeError?

Add the following to the code from this post:

# What is the type of Menu?
print(type(Menu)) # It is <class 'type'>
# Let's raise a TypeError
arepas = Menu
buggy_store = Franchise("42 Buggy Code Road", arepas)
print(buggy_store.available_menus(12))

Output on my local machine:

<class 'type'>
Traceback (most recent call last):
  File "/Users/glennrichard/Documents/BastaFazoolin.py", line 77, in <module>
    print(buggy_store.available_menus(12))
  File "/Users/glennrichard/Documents/BastaFazoolin.py", line 28, in available_menus
    for menu in self.menus:
TypeError: 'type' object is not iterable

The above is probably not exactly what happened, but it might provide some insight.

Edited on June 1, 2020 to acknowledge that we can only guess what happened to raise the original error

2 Likes

Hi! As with testing the last few lines of code (arepa!) I followed the project walk through video ([Video]).

My apera code section:

#Apres
arepas_items = {
  'arepa pabellon': 7.00, 'pernil arepa': 8.50, 'guayanes arepa': 8.00, 'jamon arepa': 7.50
}
arepas_menu = Menu("Take a' Arepa", arepas_items, 1000, 2000)

arepas_place = Franchise("189 Fitzgerald Avenue", [arepas_menu])

arepa = Business("Take a' Arepa", [arepas_place])

print(arepa.franchises[0])

But I’m getting an error as below:

arepa = Business(“Take a’ Arepa”, [arepas_place])
TypeError: ‘Business’ object is not callable

In the video, he doesn’t get this error and so I’m not sure what’s happening.

Did you get any errors when you tested the code?

Hello, @sobhankalantari62148, and welcome to the Codecademy Forums!

Please post the code from your definition of the Business class, so that we can identify the source of the problem.

Hi! Thanks for getting in touch, here’s the complete code:

class Business:

  def __init__(self, name, franchises):
    self.name = name
    self.franchises = franchises

class Franchise:
  
  def __init__(self, address, menus):
    self.address = address
    self.menus = menus
  
  def __repr__(self):
    return self.address
  
  def available_menus(self, time):
    available_menu = []
    for menu in self.menus:
      if  menu.start_time <= time and time <= menu.end_time:
        available_menu.append(menu)
    return available_menu

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) + " " + str(self.end_time)

  def calculate_bill(self, purchased_items):
    total = 0
    for purchased_item in purchased_items:
      if purchased_item in self.items:
        total += self.items[purchased_item]
    print(total)

brunch_items = {
  '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
}
early_bird_items = {
  '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,
}
dinner_items = {
  '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,
}
kids_items = {
  'chicken nuggets': 6.50, 'fusilli with wild mushrooms': 12.00, 'apple juice': 3.00
}


brunch = Menu("Brunch", brunch_items, 1100, 1600)

early_bird = Menu("Early Bird", early_bird_items, 1500, 1800)

dinner = Menu("Dinner", dinner_items, 1700, 2300)

kids = Menu("Kids", kids_items, 1100, 2100)



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

menus = [brunch, early_bird, dinner, kids]
  

flagship_store = Franchise("1232 West End Road", menus)
new_installment = Franchise("12 East Mulberry Street", menus)

print(flagship_store.available_menus(1700))

franchises_list = [flagship_store, new_installment]

Business = Business("Basta Fazoolin' with my Heart", franchises_list)

#Apres
arepas_items = {
  'arepa pabellon': 7.00, 'pernil arepa': 8.50, 'guayanes arepa': 8.00, 'jamon arepa': 7.50
}
arepas_menu = Menu("Take a' Arepa", arepas_items, 1000, 2000)

arepas_place = Franchise("189 Fitzgerald Avenue", [arepas_menu])

arepa = Business("Take a' Arepa", [arepas_place])

print(arepa.franchises[0])

Thanks

Hi @sobhankalantari62148,

In this line, you have overwritten your definition of the Business class with an instance of that class:

Business = Business("Basta Fazoolin' with my Heart", franchises_list)

After that, you cannot use Business to instantiate a new instance, so this line raises a TypeError:

arepa = Business("Take a' Arepa", [arepas_place])
2 Likes

I see now! Thanks for your help!

2 Likes

So, I made it to step 11 and am getting an error:

Traceback (most recent call last):
File “script.py”, line 51, in
print(early_bird_menu.calculate_bill([‘salumeria plate’,‘mushroom ravioli (vegan)’]))
AttributeError: ‘tuple’ object has no attribute ‘calculate_bill’

when I try and use this code:
print(early_bird_menu.calculate_bill(['salumeria plate','mushroom ravioli (vegan)']))

But, in task 10, I got no error from this code:
print(brunch_menu.calculate_bill(['pancakes','home fries','coffee']))

I can’t figure out why one is throwing the error and the other isn’t. I even checked the walkthrough video, and got no hint.

What type of object is .calculate_bill supposed to be used on?

Actually, can you post your entire code?

Sure:

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+ " items are available from " + str(self.start_time) + " to " + str(self.end_time)

  def calculate_bill(self,purchased_items):

    bill = 0

    for item in purchased_items:

      if item in self.items:

        bill+=self.items[item]

    return bill

# Brunch Menu

brunch_items = {

  '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

}

brunch_menu = Menu('Brunch',brunch_items,1100,1600)

# Early Bird Menu

early_bird_items = {

  '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,

}

early_bird_menu = ('Early-Bird', early_bird_items,1500,1800)

# Dinner Menu

dinner_items = {

  '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,

}

dinner_menu = ('Dinner',dinner_items,1700,2300)

# Kids Menu

kids_items = {

  'chicken nuggets': 6.50, 'fusilli with wild mushrooms': 12.00, 'apple juice': 3.00

}

kids_menu = ('Kids Menu',kids_items,1100,2100)

#print(brunch_menu)

print(brunch_menu.calculate_bill(['pancakes','home fries','coffee']))

print(early_bird_menu.calculate_bill(['salumeria plate','mushroom ravioli (vegan)']))

And like I say, the only thing that threw an error was the last attempt to calculate the early bird bill.

There’s something quite different between the assignment to brunch_menu and to some of the similar names. Have a close look at your expressions for these lines.

3 Likes

Oh my God. I can’t believe I missed that. Thank you.

2 Likes