VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • python基础教程之编写类-餐馆类

# Author Eric Zhao 
# -*- coding:utf-8 -*-
class Restaurant():
    """ 餐馆类 """
    def __init__(self,restaurant_name,cuisine_type):
        """ 始化属性 restaurant,cuisine_type """
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type
        self.number_served = 100

    def describe_restaurant(self):
        """ 方法:餐馆描述"""
        print("\n" + self.restaurant_name.title() + " is located on Northeast Street 4.")
        print("Cuisine type is "+self.cuisine_type.title()+"!")

    def open_restaurant(self):
        """  方法:餐馆营业 """
        print(self.restaurant_name.title() + " is open. ")

    def read_number_served(self):
        """  方法:打印已经在餐馆就餐过的人数 """
        print('We have served '+ str(self.number_served) + ' guests and you will be next.')

    def set_number_served(self,new_number):
        """ 方法:设置就餐人数 """
        if self.number_served < new_number:
            self.number_served = new_number
        print('set_num We have served ' + str(self.number_served) + ' guests and you will be next.')

    def increment_number_served(self,incr_num):
        """ 方法:增加就餐人数 """
        if incr_num >= 1:
            self.number_served += incr_num
        print('incr_num We have served ' + str(self.number_served) + ' guests and you will be next.')




northeast_restaurant = Restaurant('Big Pot Fish','stewing')
northeast_restaurant.describe_restaurant()
northeast_restaurant.read_number_served()
northeast_restaurant.set_number_served(50)
northeast_restaurant.increment_number_served(30)

northwest_restaurant = Restaurant('Northwest Beef Ramen','baking')
northwest_restaurant.describe_restaurant()
northwest_restaurant.read_number_served()

'''
sichuan_restaurant = Restaurant('Sichuan Imperial Palace','chili')
sichuan_restaurant.describe_restaurant()
sichuan_restaurant.read_number_served()
'''

相关教程