首页 > 其他 > 详细

编写类-餐馆类

时间:2019-05-24 14:28:37      阅读:113      评论:0      收藏:0      [点我收藏+]
# 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()
‘‘‘

编写类-餐馆类

原文:https://www.cnblogs.com/abarcher/p/10917856.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!