赞
踩
9-1 餐馆:
创建一个名为Restaurant的类,其方法__init__()设置两个属性:restaurant_name和cuisine_type。创建一个名为describe_restaurant()的方法和一个名为open_restaurant()的方法,其中前者打印前述两项信息,而后者打印一条消息,指出餐馆正在营业。
class Restaurant: def __init__(self,restaurant_name,cuisine_type): self.restaurant_name =restaurant_name self.cuisine_type = cuisine_type self.number_served = 0 def describe_restaurant(self): print("\nThis restaurant's name is " + self.restaurant_name) print("it's type is " + self.cuisine_type) def open_restaurant(self): print('\nThe restaurant is open') restaurant = Restaurant('xixili','yinshi') print(restaurant.restaurant_name) print(restaurant.cuisine_type) restaurant.describe_restaurant() restaurant.open_restaurant()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。