#9.1
class Restaurant():
def __init__(self,name,_type):
self.name = name
self._type = _type
self.num = 0
def des_res(self):
print("Resturant's name: "+self.name+"\ncuisine type: "+self._type)
def open_res(self):
print("The resturant is open")
def set_num(self,nums):
self.num = nums
def incre_num(self,nums):
self.num += nums
restaurant = Restaurant("LZLM","noodle")
print(restaurant.name+' '+restaurant._type)
restaurant.des_res()
restaurant.open_res()
#9.2
rest_1 = Restaurant("McDonald","fast food")
rest_2 = Restaurant("mxgjrj","Mexico's")
rest_1.des_res()
rest_2.des_res()
#9.4
rest_3 = Restaurant("CF","Yuecai")
print("There are "+str(rest_3.num)+" people")
rest_3.set_num(100)
print("There are "+str(rest_3.num)+" people")
rest_3.incre_num(6)
print("There are "+str(rest_3.num)+" people")
#9.6
class IceCream(Restaurant):
def __init__(self,name,_type,names):
super().__init__(name,_type)
self.flavors = names
def IC_show(self):
print("there are these ics cream: ")
print(self.flavors)
flavor = ['Apple','Banana','Orange','Watermelon']
ice_store = IceCream('SHA','Cream',flavor)
ice_store.des_res()
ice_store.IC_show()
模板
hw_8_restaurant.py
class Restaurant():
def __init__(self,name,_type):
self.name = name
self._type = _type
self.num = 0
def des_res(self):
print("Resturant's name: "+self.name+"\ncuisine type: "+self._type)
def open_res(self):
print("The resturant is open")
def set_num(self,nums):
self.num = nums
def incre_num(self,nums):
self.num += nums
实例
from hw_8_restaurant import Restaurant
restaurant = Restaurant("LZLM","noodle")
print(restaurant.name+' '+restaurant._type)
restaurant.des_res()
restaurant.open_res()
restaurant.set_num(100)
print("There are "+str(restaurant.num)+" people")
restaurant.incre_num(6)
print("There are "+str(restaurant.num)+" people")