0
点赞
收藏
分享

微信扫一扫

python从入门到实践练习9-6:冰淇淋小店

阎小妍 2022-04-02 阅读 43
python

python从入门到实践练习9-6:冰淇淋小店

class Restaurant:
    '''一次一个模拟餐馆的简单尝试'''
    def __init__(self,restaurant_name,cuisine_type):
        '''初始化餐馆的名字和烹饪类型风味'''
        self.name = restaurant_name
        self.type = cuisine_type
    def describe_restaurant(self):
        '''打印餐馆的名字和烹饪类型风味'''
        print(f'\nThere have a restaurant called {self.name}')
        print(f'The restaurant flavor is {self.type}!')
    def open_restaurant(self):
        '''描述各自餐馆正在营业'''
        print(f'\nThere have a restaurant called {self.name} is open here')

class IceCreamStand(Restaurant):
    '''冰淇淋小店特殊之处'''
    def __init__(self,restaurant_name,cuisine_type):
        '''初始化父类的属性
           再初始化冰淇淋小店特有属性
        '''
        super().__init__(restaurant_name,cuisine_type)

        self.flavor = ['VANILLA','CHOCOLATE','COFFER',\
    'STRAWBERRY','MATCHA','RUM RAISIN','DULCE DE LECHE','MANGO',\
    'APRICOT','TIRAMISU','BALLEYS']

    def describe_flavor(self):
        '''打印一条描述冰淇淋口味的消息'''
        print(f'We have {self.flavor} flavors of ice cream on sale.')

IceCreamStand = IceCreamStand('Ice wonder','Small shop')

print(IceCreamStand.describe_restaurant())

IceCreamStand.describe_flavor()

IceCreamStand.open_restaurant()

运行结果如下
在这里插入图片描述

举报

相关推荐

0 条评论