9-6 冰淇淋小店:冰淇淋小店是一種特殊的餐館。編寫一個名爲 IceCreamStand 的
類,讓它繼承你爲完成練習 9-1 或練習 9-4 而編寫的 Restaurant 類。這兩個版本的
Restaurant 類都可以,挑選你更喜歡的那個即可。添加一個名爲 flavors 的屬性,用於
存儲一個由各種口味的冰淇淋組成的列表。編寫一個顯示這些冰淇淋的方法。創建一個
IceCreamStand 實例,並調用這個方法。
class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.restaurant_name=restaurant_name
self.cuisine_type=cuisine_type
def describe_restaurant(self):
print(self.restaurant_name)
print(self.cuisine_type)
def open_restaurant(self):
print('This restaurant is open.')
class IceCreamStand(Restaurant):
def __init__ (self,restaurant_name,cuisine_type):
super().__init__(restaurant_name,cuisine_type)
self.flavors=['cool','hot','nice']
def show_flavors(self):
for n in self.flavors:
print('my favorate taste is '+n)
weilianxin=IceCreamStand('fengwei','ICE')
weilianxin.show_flavors()