1 问题
图 1 问题 9 − 2 图1~ 问题9-2 图1 问题9−2
2 代码及其输出
# 9-2
class Restaurant:
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print("restaurant_name is " + self.restaurant_name.title())
print("cuisine_type is " + self.cuisine_type.title())
def open_restaurant(self):
print("restaurant is opening")
resturant_1 = Restaurant("001", "中餐")
resturant_2 = Restaurant("002", "西餐")
resturant_3 = Restaurant("003", "中餐")
# Answer question
resturant_1.describe_restaurant()
resturant_2.describe_restaurant()
resturant_3.describe_restaurant()
# output
restaurant_name is 001
cuisine_type is 中餐
restaurant_name is 002
cuisine_type is 西餐
restaurant_name is 003
cuisine_type is 中餐