• 练习 创建餐馆类


    # -*- conding:utf-8 -*-
    class Restaurant():
    
        #构造方法
        def __init__(self,restaurant_name,cuisine_type,number_served=0):
            self.restaurant_name =restaurant_name #餐馆名
            self.cuisine_type =cuisine_type #烹饪类型
            self.number_served = number_served #就餐人数
        #餐馆信息
        def describe_restaurant(self):
            print('这家餐馆的名字:%s餐馆'%(self.restaurant_name))
            print('这家餐馆烹饪的类型:%s' % (self.cuisine_type))
        def open_restaurant(self):
            print('%s餐馆正常营业'%(self.restaurant_name))
        #设置就餐人数
        def set_number_served(self,n):
            self.number_served = n
            print('当前就餐人数为:%d'%n)
        #递增就餐人数
        def increment_number_served(self,n):
            for i in range(1,n+1):
                self.number_served +=1
                print('当前就餐人数为:%d' % self.number_served)
    
    #实例化
    restaurant_name1 = Restaurant('人民','炒菜')
    # restaurant_name1.describe_restaurant()
    # restaurant_name1.open_restaurant()
    # chuancai = Restaurant('四川火锅','火锅')
    # chuancai.describe_restaurant()
    # yangRouTang = Restaurant('单县羊肉汤','羊肉汤')
    # yangRouTang.describe_restaurant()
    print('就餐人数为:%d'%(restaurant_name1.number_served))
    restaurant_name1.number_served=10
    print('就餐人数为:%d'%(restaurant_name1.number_served))
    restaurant_name1.set_number_served(12)
    restaurant_name1.increment_number_served(10)
  • 相关阅读:
    nodejs ---day01
    面向对象
    面向对象
    面向对象
    webpack
    webpack
    webpack
    模块化 (ESM) --- day02
    模块化 --- day01
    轮播图(淡入淡出切换)
  • 原文地址:https://www.cnblogs.com/xyg-zyx/p/8884357.html
Copyright © 2020-2023  润新知