练习 9.1 餐馆
创建一个名为Restaurant的类,为其__init__()方法设置两个属性: restaurant_name
和cuisine_type。创建一个名为describe_restaurant()的方法和一个名为
open_restaurant()的方法,其中前者打印前述两项信息,而后者打印一条消息,指出餐馆
正在营业。
根据这个类创建一个名为restaurant的实例,分别打印其两个属性,再调用前述两个方
法。
class Restaurant:
def __init__(self, name, cuisine_type):
self.name = name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(f'餐厅名字是:{self.name},它们提供菜品是:{self.cuisine_type}')
def open_restaurant(self):
print(f'{self.name}餐厅正在营业...')
restaurant = Restaurant('KFC', '快餐')
print(restaurant.name)
print(restaurant.cuisine_type)
restaurant.describe_restaurant()
restaurant.open_restaurant()
输出:
KFC
快餐
餐厅名字是:KFC,它们提供菜品是:快餐
KFC餐厅正在营业...