Hello
I’m at the almost end of python3 course and get stuck on this problem.
This is my course and this is my error place.
from datetime import time
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 "Our menu's name is {name}. You can order it from {start_time} to {end_time}".format(name = self.name, start_time = self.start_time, end_time = self.end_time)
def calculate_bill(self, purchased_items):
sum = 0
for bought in purchased_items:
if bought not in self.items.keys():
print("You bought something wrong")
else:
sum += self.items[bought]
return sum
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("Brunch", brunch_items, time(11,0), time(16,0))
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, time(15,0), time(18,0))
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, time(17,0), time(23,0))
kids_items = {
'chicken nuggets': 6.50, 'fusilli with wild mushrooms': 12.00, 'apple juice': 3.00
}
kids = Menu("Kids", kids_items, time(11,0), time(21,0))
class Franchise:
def __init__(self, address, menus):
self.address = address
self.menus = menus
def __repr__(self):
return "Our restraunt is located on {address}".format(address = self.address)
def available_menus(self, time):
for menu in self.menus:
if menu.start_time <= time <= menu.end_time:
print("We can serve {name} menu, sir.".format(name = menu.name.lower()))
else:
continue
flagship_store = Franchise("1232 West End Road", [brunch, early_bird, dinner, kids_items])
new_installment = Franchise("12 East Mulberry Street", [brunch, early_bird, dinner, kids_items])
flagship_store.available_menus(time(15,0))
And as you can see, if start_time of Menu instance is later than time argument of Franchise class’s available_menus. They say ‘AttributeError: ‘dict’ object has no attribute ‘start_time’’. But when I see the datatype of ‘menu.start_time’ and ‘menu.end_time’ in function, it’s not dictionary.
I can solve the problem with exception, but want to know the essential reason why my code doesn’t work. Help! S.O.S