第五周作业a 第9章选做(1、2、6、10)

本文通过Python代码实现了一个餐厅类,并展示了如何通过继承创建冰淇淋店子类,同时介绍了不同实例的用法。

9-1

#9.1
class Restaurant():
	def __init__(self,name,cuisine_type):
		self.name=name
		self.cuisine_type=cuisine_type
	def describe_restaurant(self):
		print("The restaurant's name is "+self.name+ ".")
		print("The restaurant's cuisine type is "+self.cuisine_type+".")
	def open_restaurant(self):
		print("The restaurant is open now.")

9-2

#9.2
restaurant_a=Restaurant('A','type_A')
restaurant_a.describe_restaurant()
	
restaurant_b=Restaurant('B','type_B')
restaurant_b.describe_restaurant()
	
restaurant_c=Restaurant('C','type_C')
restaurant_c.describe_restaurant()

   

9-6

#9.6
#coding=gbk
class Restaurant():
	def __init__(self,name,cuisine_type):
		self.name=name
		self.cuisine_type=cuisine_type
	def describe_restaurant(self):
		print("The restaurant's name is "+self.name+ ".")
		print("The restaurant's cuisine type is "+self.cuisine_type+".")
	def open_restaurant(self):
		print("The restaurant is open now.")

class IceCreamStand(Restaurant):
	def __init__(self,name,cuisine_type):
		super().__init__(name,cuisine_type)
		self.flavors={"flavor_1,flavor_2,flavor_3"}
	def show_flavors(self):
		print('含以下口味的冰淇淋:')
		print(self.flavors)

ice=IceCreamStand("IceCreamStand","icecream")
ice.describe_restaurant()
ice.open_restaurant()
ice.show_flavors()

9.10

#9.10
import restaurant 

my_restaurant = restaurant.Restaurant("a","b")
my_restaurant.describe_restaurant()
my_restaurant.open_restaurant()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值