1 问题
图
1
问题
9
−
1
图1~ 问题9-1
图1 问题9−1
2 代码及其输出
# 9-1
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")
restaurant = Restaurant("费大厨", "中餐")
# print attributes
print("restaurant's name is " + restaurant.restaurant_name.title())
print("restaurant's cuisine-type is " + restaurant.cuisine_type)
# Calling method
restaurant.describe_restaurant()
restaurant.open_restaurant()
# output
restaurant's name is 费大厨
restaurant's cuisine-type is 中餐
restaurant_name is 费大厨
cuisine_type is 中餐
restaurant is opening