欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

第九章

程序员文章站 2022-05-30 17:44:24
...

9-1

class Restaurant():
	def __init__(self, name, type_,number_served = 0 ):
		self.restaurant_name = name
		self.cuisine_type = type_
		self.number_served = number_served
		
	def describe_restaurant(self):
		print(self.restaurant_name)
		print(self.cuisine_type)
		
	def open_restaurant(self):
		print('The restaurant is open.')

restaurant = Restaurant('KFC', 'Fast Food')
print(restaurant.restaurant_name)
print(restaurant.cuisine_type)
restaurant.describe_restaurant()
restaurant.open_restaurant()

9-2

AAA = Restaurant('AAA', 'Chinese Food')
BBB = Restaurant('BBB', 'Western Fodd')
CCC = Restaurant('CCC', 'Dessert')

9-4

class Restaurant():
	def __init__(self, name, type_,number_served = 0 ):
		self.restaurant_name = name
		self.cuisine_type = type_
		self.number_served = number_served
		
	def describe_restaurant(self):
		print(self.restaurant_name)
		print(self.cuisine_type)
		
	def open_restaurant(self):
		print('The restaurant is open.')
	
	def set_number_served(self, number):
		self.number_served = number
		
	def increment_number_served(self, number):
		self.number_served += number

print(str(restaurant.number_served) + ' persons had meals in this restaurant.')
restaurant.number_served = 15
print(str(restaurant.number_served) + ' persons had meals in this restaurant.')

restaurant.set_number_served(20)
print(restaurant.number_served)

restaurant.increment_number_served(50)
print(restaurant.number_served)

9-6

class IceCreamStand(Restaurant):
	def __init__(self, name, type_, flavours, number_served = 0):
		super().__init__(name, type_,number_served = 0)
		self.flavours = flavours
		
	def display_flavours(self):
		for flavour in self.flavours:
			print(flavour)
			
ice = IceCreamStand('ice', 'ice-cream', flavours = ['strawberry', 'melon', 'apple'])
ice.display_flavours()

9-10

from restaurant import Restaurant

MHK = Restaurant('MHK', 'Japanese Food', 100)
MHK.describe_restaurant()