9-1. Restaurant: Make a class called Restaurant. The __init__() method for Restaurant should store two attributes: a restaurant_name and a cuisine_type. Make a method called describe_restaurant() that prints these two pieces of information, and a method called open_restaurant() that prints a message indicating that the restaurant is open. Make an instance called restaurant from your class. Print the two attributes individually, and then call both methods.
9-2. Three Restaurants: Start with your class from Exercise 9-1. Create three different instances from the class, and call describe_restaurant() for each instance.
代码:
#9-1 & 9-2
class Restaurant():
def __init__(self, restaurant_name, cuisine_name):
self.restaurant_name = restaurant_name
self.cuisine_name = cuisine_name
def describe_restaurant(self):
print("Restaurant name: " + self.restaurant_name.title())
print("Cuisine name: " + self.cuisine_name.title())
def open_restaurant(self):
print(self.restaurant_name.title()+" is open")
kfc = Restaurant('kfc', 'chicken')
mc = Restaurant('MCDonald', 'beef')
king = Restaurant('burger king', 'ham')
kfc.describe_restaurant()
kfc.open_restaurant()
mc.describe_restaurant()
mc.open_restaurant()
king.describe_restaurant()
king.open_restaurant()
注意:“成员函数”参数勿忘加self & 访问“成员变量”时要加self
9-4. Number Served: Start with your program from Exercise 9-1.
Add an attribute called number_served with a default value of 0. Create an inst