【日常Python-14】类3

任务1.冰淇淋小店

  1. 问题描述
    冰淇淋小店是一种特殊的餐馆。编写一个名为IceCreamStand 的类,让它继承Restaurant 类。添加一个名为flavors 的属性,用于存储一个由各种口味的冰淇淋组成的列表。编写一个显示这些冰淇淋的方法。创建一个IceCreamStand 实例,并调用这个方法。
  2. 源代码
# coding:gbk
class Restaurant():
	"""restaurant information"""

	def __init__(self, restaurant_name, cuisine_type):
		"""Init."""
		self.restaurant_name = restaurant_name
		self.cuisine_type = cuisine_type

	def describe_restaurant(self):
		""""Returns clean description information."""
		print("\n 餐厅名称: " + self.restaurant_name)
		print("\n 菜式: " + self.cuisine_type)

	def open_restaurant(self):
		print("The restaurant is open now.")
		
class IceCreamStand(Restaurant):
	
	def __init__(self, restaurant_name, cuisine_type):
		super().__init__(restaurant_name, cuisine_type)
		
	def icecreamstand(self):
		self.flavors = ['Apple', 'Pear', 'Banana']
		return self.flavors
	
restaurant = Restaurant('Hong Kong style tea restaurant', 'Roast goose rice')
restaurant.describe_restaurant()
restaurant.open_restaurant()
print("My favorite restaurant is " + restaurant.restaurant_name.title() + ".")
print("The restaurant cuisine is " + restaurant.cuisine_type.title() + ".")

ics = IceCreamStand('Hong Kong style tea restaurant', 'Roast goose rice')
ics.icecreamstand()
print(ics.icecreamstand())
  1. 结果截图
    在这里插入图片描述

任务2.管理员

  1. 问题描述
    管理员是一种特殊的用户。编写一个名为Admin 的类,让它继承你为完成练习9-3或练习9-5而编写的User 类。添加一个名为privileges 的属性,用 于存储一个由字符串(如"can add post" 、“can delete post” 、“can ban user” 等)组成的列表。编写一个名为show_privileges() 的方法,它 显示管理员的权限。创建一个Admin 实例,并调用这个方法。
  2. 源代码
  3. </
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值