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

代码如下

class Restaurant():
    def __init__(self,restaurant_name,cuisine_type):
        #self.属性 的作用获取形参restaurant_name的值,并存储到restaurant_name中
        #以供实例使用
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type
        self.number_served = 20

    def set_number_served(self,set_number):
        #使用方法设置number_served属性的值
        self.number_served = set_number

    def increment_number_served(self,increment_number):
        self.number_served += increment_number

    def describe_restaurant(self):
        print('您所在的餐厅是:' + self.restaurant_name +
              ',餐饮类型是:' + self.cuisine_type +
              ',就餐人数为:' + str(self.number_served) +
              '人')

    def open_restaurant(self):
        print('餐厅正在营业!')

class IceCreamStand(Restaurant):

    def __init__(self,restaurant_name,cuisine_type):
        super().__init__(restaurant_name,cuisine_type)
        #给子类设置新的属性
        self.flavors = ['草莓味','苹果味','原味奶油']

    def describe_icecream(self):
        print('\n本店提供的冰激凌有' + '3种:')
        for show_flavors in self.flavors:
            print(show_flavors)
#9-6 冰淇淋小店
my_icecream = IceCreamStand('梦想之家','冰激凌')
my_icecream.set_number_served(15)
my_icecream.increment_number_served(35)
my_icecream.describe_restaurant()
my_icecream.describe_icecream()
    原文作者:Max-Init
    原文地址: https://blog.csdn.net/qq_14936041/article/details/77688819
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞