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')
    

      

  • 相关阅读:
    微软Silverlight 2.0 最新版本GDR发布
    POJ 2635, The Embarrassed Cryptographer
    POJ 3122, Pie
    POJ 1942, Paths on a Grid
    POJ 1019, Number Sequence
    POJ 3258, River Hopscotch
    POJ 3292, Semiprime Hnumbers
    POJ 2115, C Looooops
    POJ 1905, Expanding Rods
    POJ 3273, Monthly Expense
  • 原文地址:https://www.cnblogs.com/kevin-hou1991/p/14942329.html
Copyright © 2011-2022 走看看