zoukankan      html  css  js  c++  java
  • 9-6 冰淇淋小店

    1. 项目

    冰淇淋小店是一种特殊的餐馆。编写一个名为 IceCreamStand 类,让它继承你为完成练习 9-1 或练习 9-4 而编写的 Restaurant 类。

    这两个版本的Restaurant 类都可以,挑选你更喜欢的那个即可。添加一个名为 flavors 的属性,用于存储一个由各种口味的冰淇淋组成的列表。

    编写一个显示这些冰淇淋的方法。创建一个IceCreamStand 实例,并调用这个方法。

     

    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 " + self.restaurant_name + " have " +
                  str(self.cuisine_type) + " kinds of food.")
    
        def open_restaurant(self):
            print("Now is opening.")
    
    """创建flavors列表用于存储各种冰淇淋列表"""
    flavors = ('a', 'b', 'c')
    class IceCreamStand(Restaurant):
        """初始化子类属性"""
        def __init__(self, restaurant_name, cuisine_type):
            """继承父类属性"""
            super().__init__(restaurant_name, cuisine_type)
            """添加flavors属性"""
            self.flavors = flavors
    
        def display_ICS(self):
            """显示冰淇淋的方法"""
            print(self.flavors)
    
    """创建实例化"""
    ics = IceCreamStand('KFC', 100)
    """调用方法"""
    ics.display_ICS()
    

      

    3. 执行结果

    ('a', 'b', 'c')
    

      

  • 相关阅读:
    5.11实例应用
    VS2015调试
    4.4空间平滑
    4.3图像噪声
    4.2 傅里叶变换
    4.1 图像采样
    4.5.实例应用
    关于split和merge出错问题解决
    Ansible用于网络设备管理 part 3 使用NAPALM成品库
    记办公室小机房停电
  • 原文地址:https://www.cnblogs.com/kevin-hou1991/p/14942329.html
Copyright © 2011-2022 走看看