0
我想調用一個方法,將返回冰淇淋攤的味道。下面是我的代碼:Python的繼承和調用方法
class Restaurant:
"""Defining Restaurants"""
def __init__ (self, restaurant_name, cuisine_type):
"""Initializing a restaurant name and cuisine type"""
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
self.number_served = 545
def describe_restaurant(self):
"""Describing the restaurant"""
print(self.restaurant_name.title() + " serves " + self.cuisine_type.title() + ".")
def open_restaurant(self):
"""Stating the restaurant is open"""
print(self.restaurant_name.title() + " is now open.")
def set_number_served(self):
"""Method that sets the number served"""
set_number_served = 430
print("This restaurant has served " + str(set_number_served) + " customers.")
def restaurant(self):
"""Statement showing how many customers have been served"""
print("This restaurant has served " + str(self.number_served) + " customers.")
def increment_number_served(self):
self.number_served += 432
print("This restaurant has served " + str(self.number_served) + " customers.")
class IceCreamStand(Restaurant):
"""Represents an ice cream stand"""
def __init__(self, restaurant_name, cuisine_type, flavors):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
self.flavors = flavors
def flavors(self):
"""Flavors of ice cream"""
flavors = ['chocolate', 'vanilla', 'strawberry']
for flavor in flavors:
return flavor.title()
my_IceCreamStand = IceCreamStand('West Ice Cream', 'Dessert', 'multiple')
my_IceCreamStand.flavors()
我收到的錯誤是:
Traceback (most recent call last):
File "ice_Cream_Stand.py", line 45, in <module>
my_IceCreamStand.flavors()
任何想法?
類型錯誤:「海峽」對象不是可調用
太棒了,就是這樣!謝謝你! –