Python练习题 9-6冰激凌小店

9-6 冰淇淋小店 :冰淇淋小店是一种特殊的餐馆。编写一个名为 IceCreamStand 的 
类,让它继承你为完成练习 9-1 或练习 9-4 而编写的 Restaurant 类。这两个版本的 
Restaurant 类都可以,挑选你更喜欢的那个即可。添加一个名为 flavors 的属性,用于 
存储一个由各种口味的冰淇淋组成的列表。编写一个显示这些冰淇淋的方法。创建一个 
IceCreamStand 实例,并调用这个方法。
class Restaurant():
 def __init__(self,restaurant_name,cuisine_type):
    self.restaurant_name = restaurant_name
    self.cuisine_type = cuisine_type
    self.number_served=0
 def describe_restaurant(self):
     print(self.restaurant_name)
     print(self.cuisine_type)
 def open_restaurant(self):
     print("This restaurant is open")
class IceCreamStand(Restaurant):
    def __init__(self,restaurant_name,cuisine_type):
        """IceCreamStand 的独特之处
        初始化父类的属性,再初始化IceCreamStand特有的属性 """
        super().__init__(restaurant_name,cuisine_type)
        self.flavors=['strawberry','banana','milk']
    def show_flavors(self):
         for n in self.flavors:
           print("My flavors is "+ n)
my_icecream=IceCreamStand("MXF","fastfood")
my_icecream.show_flavors()

你可能感兴趣的:(1)