您的位置:首页 > 编程语言

高级编程作业 第九章

2018-04-06 19:17 435 查看
#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.pyclass 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")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: