#9-1 餐馆 :创建一个名为Restaurant 的类,其方法__init__() 设置两个属性:restaurant_name 和cuisine_type 。
#创建一个名为describe_restaurant() 的方法和一个名为open_restaurant() 的方法,
#其中前者打印前述两项信息,而后者打印一条消息,指出餐馆正在营业。
#根据这个类创建一个名为restaurant 的实例,分别打印其两个属性,再调用前述两个方法。
class Restaurant():
"""一个餐馆的简单尝试"""
def __init__(self, restaurant_name,cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_rastaurant(self):
print(self.restaurant_name)
print(self.cuisine_type)
def open_restaurant(self):
print('餐馆正在营业!')
restaurant = Restaurant('绯羽','中式')
print('我的餐馆名称为:',restaurant.restaurant_name)
print('烹饪方法为:',restaurant.cuisine_type)
restaurant.describe_rastaurant()
restaurant.open_restaurant()
#9-2 三家餐馆 :根据你为完成练习9-1而编写的类创建三个实例,并对每个实例调用方法de
Python编程从入门到实践:习题9-1~9-3
最新推荐文章于 2024-04-02 05:34:35 发布