练习9-1:餐馆 创建一个名为Restaurant 的类,为其方法__init__()
设置属性restaurant_name 和cuisine_type 。创建一个名为
describe_restaurant() 的方法和一个名为open_restaurant() 的方
法,前者打印前述两项信息,而后者打印一条消息,指出餐馆正在营业。
根据这个类创建一个名为restaurant 的实例,分别打印其两个属性,再调用
前述两个方法。
class Restaurant:
def __init__(self, restaurand_name, cuisine_type):
self.restaurant_name = restaurand_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(f"这个餐馆的名字是{self.restaurant_name},菜系是{self.cuisine_type}")
def open_restaurant(self):
print(f"{self.restaurant_name}餐馆正在营业!")
restaurant = Restaurant('好运来', '东北菜')
restaurant.describe_restaurant()
restaurant.open_restaurant()
这个餐馆的名字是好运来,菜系是东北菜
好运来餐馆正在营业!
进程已结束,退出代码0