Reputation: 1199
class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
self.name= restaurant_name
self.cuisine = cuisine_type
def describe_restaurant(self):
print(self.name.title() + ' serves ' + self.cuisine + ' food.')
def open_restaurant(self):
print(self.name.title() + ' is now open. \nCome and Have some delicious ' +self.cuisine+ ' food.' )
restaurant= Restaurant('Big Chillo', 'Italian')
restaurant.describe_restaurant()
restaurant.open_restaurant()
class cuisine(Restaurant):
def __init__(self, cuisine_type):
self.name = cuisine_type
super().__init__(cuisine_type)
def availability(self):
print ('These are the available cuisines ' + self.name.title())
menu =cuisine['Tiramisu \nCannoli \nPanna \ncotta \nCassata \nSemifreddo']
menu.availability()
File "D:/python project/restaurant.py", line 25, in Come and Have some delicious Italian food. menu =cuisine['Tiramisu \nCannoli \nPanna \ncotta \nCassata \nSemifreddo'] TypeError: 'type' object is not subscriptable
Upvotes: 0
Views: 112
Reputation: 4596
Found 3 issues with your code:
1. As mention by @FHTMitchell, Call functions / class constructors using parentheses () rather than square brackets []
2. You do not have Restaurant Constructor with 1 argument so I added extra parameter to code super().__init__("RestaurantName",cuisine_type)
3. self.name
is String so we should not call it as a function in print of availability method changed self.name()
to self.name
class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
self.name= restaurant_name
self.cuisine = cuisine_type
def describe_restaurant(self):
print(self.name.title() + ' serves ' + self.cuisine + ' food.')
def open_restaurant(self):
print(self.name.title() + ' is now open. \nCome and Have some delicious ' +self.cuisine+ ' food.' )
restaurant= Restaurant('Big Chillo', 'Italian')
restaurant.describe_restaurant()
restaurant.open_restaurant()
class cuisine(Restaurant):
def __init__(self, cuisine_type):
self.name = cuisine_type
super().__init__("hello",cuisine_type)
def availability(self):
print ('These are the available cuisines ' + self.name)
menu =cuisine('Tiramisu \nCannoli \nPanna \ncotta \nCassata \nSemifreddo')
menu.availability()
menu.describe_restaurant()
The output I got is:
Big Chillo serves Italian food. Big Chillo is now open. Come and Have some delicious Italian food. These are the available cuisines hello Hello serves Tiramisu Cannoli Panna cotta Cassata Semifreddo food. Process finished with exit code 0
Upvotes: 0
Reputation: 12157
Call functions / class constructors using parentheses ()
rather than square brackets []
menu = cuisine('Tiramisu \nCannoli \nPanna \ncotta \nCassata \nSemifreddo')
Upvotes: 1