python课后习题 9-6

9-6 冰淇淋小店:
冰淇淋小店是一种特殊的餐馆。编写一个名为IceCreamStand 的类,让它继承你为完成练习9-1 或练习9-4 而编写的Restaurant 类。这两个版本的Restaurant 类都可以,挑选你更喜欢的那个即可。添加一个名为flavors 的属性,用于存储一个由各种口味的冰淇淋组成的列表。编写一个显示这些冰淇淋的方法。创建一个IceCreamStand 实例,并调用这个方法。
(我开始晕了)

class Restaurant ():
	
	def __init__(self,restaurant_name,cuisine_type):
		self.name=restaurant_name
		self.cuisine=cuisine_type
		self.number_served=0
		
	def describe_restaurant(self):
		print(self.name+" "+self.cuisine)
	
	def open_restaurant(self):
		print("our restaurant is in business")


class IceCreamStand (Restaurant):
	
	def __init__(self,restaurant_name,cuisine_type):
		super().__init__(restaurant_name,cuisine_type)
		self.flavors=['vanilla','chocolate','strawberry']
		
	def show_icecream_flavors(self):
		for flavor in self.flavors :
			print("your icecream has "+flavor+" flavor")

myicecream=IceCreamStand('a','b')
myicecream.show_icecream_flavors()

猜你喜欢

转载自blog.csdn.net/csdn317341539/article/details/88779035
9-6