【高编作业】第九章课后题

9-1

class Restaurant():
	def __init__(self,restaurant_name, cuisine_type):
		self.restaurant_name = restaurant_name
		self.cuisine_type = cuisine_type
		
	def describe_restaurant(self):
		print('The name of the restaurant is',self.restaurant_name)
		print('The type of cuisine is',self.cuisine_type)
		
	def open_restaurant(self):
		print('The restaurant is open')

print('Lala ,Chinese food')
res = Restaurant('Lala','Chinese food')
res.describe_restaurant()
res.open_restaurant()

9-2

class Restaurant():
	def __init__(self,restaurant_name, cuisine_type):
		self.restaurant_name = restaurant_name
		self.cuisine_type = cuisine_type
		
	def describe_restaurant(self):
		print('The name of the restaurant is',self.restaurant_name)
		print('The type of cuisine is',self.cuisine_type)
		
	def open_restaurant(self):
		print('The restaurant is open')


res1 = Restaurant('Lala','Chinese food')
res1.describe_restaurant()

res2 = Restaurant('Bobo','Western food')
res2.describe_restaurant()

res3 = Restaurant('Kaka','Japanese food')
res3.describe_restaurant()

9-3

class Restaurant():
	def __init__(self,restaurant_name, cuisine_type, number_served=0):
		self.restaurant_name = restaurant_name
		self.cuisine_type = cuisine_type
		self.number_served = number_served
		
	def describe_restaurant(self):
		print('The name of the restaurant is',self.restaurant_name)
		print('The type of cuisine is',self.cuisine_type)
		
	def open_restaurant(self):
		print('The restaurant is open')
	
	def set_number_served(self,num):
		self.number_served = num
		
res = Restaurant('Lala', 'Chinese food')
print(res.number_served)
res.set_number_served(2)
print(res.number_served)

9-6

class Restaurant():
	def __init__(self,restaurant_name, cuisine_type):
		self.restaurant_name = restaurant_name
		self.cuisine_type = cuisine_type
		
	def describe_restaurant(self):
		print('The name of the restaurant is',self.restaurant_name)
		print('The type of cuisine is',self.cuisine_type)
		
	def open_restaurant(self):
		print('The restaurant is open')

class IceCreamStand(Restaurant):
	def __init__(self,restaurant_name, cuisine_type, flavour):
		super().__init__(restaurant_name, cuisine_type)
		self.flavour = flavour.copy()
		
	def display_flavour(self):
		print('The flavours of icecream are:')
		for f in self.flavour:
			print(f)
i = IceCreamStand('mama', 'icecream',
	['chocolate','coconut','strawberry'])
i.display_flavour()

猜你喜欢

转载自blog.csdn.net/weixin_40247273/article/details/79821297