任务1.冰淇淋小店
- 问题描述
冰淇淋小店是一种特殊的餐馆。编写一个名为IceCreamStand 的类,让它继承Restaurant 类。添加一个名为flavors 的属性,用于存储一个由各种口味的冰淇淋组成的列表。编写一个显示这些冰淇淋的方法。创建一个IceCreamStand 实例,并调用这个方法。 - 源代码
# 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())
- 结果截图
任务2.管理员
- 问题描述
管理员是一种特殊的用户。编写一个名为Admin 的类,让它继承你为完成练习9-3或练习9-5而编写的User 类。添加一个名为privileges 的属性,用 于存储一个由字符串(如"can add post" 、“can delete post” 、“can ban user” 等)组成的列表。编写一个名为show_privileges() 的方法,它 显示管理员的权限。创建一个Admin 实例,并调用这个方法。 - 源代码 </