Python编程从入门到实践 9-6冰淇淋小店

   冰淇淋小店是一种特殊的餐馆。编写一个名为IceCreamStand 的类,让它继承你为完成练习9-1或练习9-4而编写的Restaurant 类。这两个版 本的Restaurant 类都可以,挑选你更喜欢的那个即可。添加一个名为flavors 的属性,用于存储一个由各种口味的冰淇淋组成的列表。编写一个显示这些冰淇淋 的方法。创建一个IceCreamStand 实例,并调用这个方法。

#!/iser/bin/env python
# coding:utf-8
class Restaurant(object):
	def __init__(self,restaurant_name,cuisine_type):
		self.restaurant_name=restaurant_name
		self.cuisine_type=cuisine_type
		self.number_served=0
		self.number_serve=0
	def describe_restaurant(self):
		#描述餐厅信息
		print("The restaurant's name is "+self.restaurant_name+", and it's type is "+self.cuisine_type+".")
	def open_restaurant(self):
		#描述餐厅状态
		print("It is opening!")
	def read_restaurant(self):
		print("Now,this restaurant has "+str(self.number_served)+" people in it.")
	def increment_number_served(self,add):
		#就餐最多人数
		self.number_serve+=add
		print("It's capacity is "+str(add)+".")
	def set_number_served(self,numbers):
		#设置就餐人数
		if numbers>=self.number_served:
			self.number_served=numbers
		if numbers>=self.number_serve:
			print("The restaurant is full!")
		else:
			print("The restaurant is empty!")
class IceCreamStand(Restaurant):
	def __init__(self,restaurant_name,cuisine_type):
		super(IceCreamStand,self).__init__(restaurant_name,cuisine_type)
		self.flavors=['chocolate','Strawberry','Original']
	def describe_ice(self):
		print("The restaurant has many ice-cream:")
		for flavor in self.flavors:
			print(flavor)

restaurant=Restaurant('KFC','fast food')
restaurant.describe_restaurant()
restaurant.open_restaurant()
restaurant.increment_number_served(100)
restaurant.set_number_served(40)
restaurant.read_restaurant()

ice_cream=IceCreamStand('HunberKing','fast food')
ice_cream.describe_ice()

结果为:

Python编程从入门到实践 9-6冰淇淋小店_第1张图片

你可能感兴趣的:(Python练习)