class Restaurant:
def __init__(self, restaurant_name,
cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
self.number = 0
def describe_restaurant(self):
print("The name of the restaurant:")
print(self.restaurant_name.title())
print("Cuisine type in this restaurant is:")
print(self.cuisine_type.title())
def set_number_served(self, number_seats):
self.number = number_seats
def number_served(self):
print(" It is the number of reserved seats:")
print("\t\t" + str(self.number))
def increment_number_served(self, number_visitors):
print("The number of served visitors per day:")
print("\t\t" + str(number_visitors))
def open_restaurant(self):
print("The restaurant is open!")
data_restaurant = Restaurant("'sushi-bar'", "'japanese cuisine'")
data_restaurant.describe_restaurant()
data_restaurant.set_number_served(2)
data_restaurant.number_served()
data_restaurant.increment_number_served(29)
print( )
data_restaurant.open_restaurant()
print("\n")
print("-----------------------------------------------")
restaurant = Restaurant("'live food'", "'raw food diet'")
restaurant.describe_restaurant()
restaurant.set_number_served(5)
restaurant.number_served()
restaurant.increment_number_served(18)
print( )
restaurant.open_restaurant()
print("\n\n")
print("----------------------------------------------")
class IceCream(Restaurant):
def __init__(self, restaurant_name, cuisine_type):
super().__init__(restaurant_name, cuisine_type)
def flavors(self, ingredients=['limon', 'vanilla', 'chocolate', 'mango']):
print("We have follow ice creams:")
print( )
print(ingredients)
my_icecream = IceCream("'funny ice'", "'ice cream restaurant'")
print(my_icecream.describe_restaurant())
my_icecream.flavors()
2 ответа
Запустил ваш код и там вывело много строк, но среди них было:
...
Cuisine type in this restaurant is:
'Ice Cream Restaurant'
None
...
We have follow ice creams:
Думаю, вас именно строка интересовала.
А причина в том, что у вас выводится:
print(my_icecream.describe_restaurant())
Метод describe_restaurant
ничего не возвращает явно, поэтому из него вернется None
Для IceCream вы делаете так:
print(my_icecream.describe_restaurant())
А для объектов родительского класса так:
restaurant.describe_restaurant()
Видите разницу? В одном случае вы просты вызываете метод, а во втором делает print результата для этого метода.
И в том, и в другом случае метод выполняется, печатает информацию о ресторане, и возвращает None.
Вот только в одном случае с этим None больше уже ничего не происходит, а во втором случае print выводит его вам.