高级编程作业 第九章

#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")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值