|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
class Restaurant:
'''餐馆的描述'''
def __init__(self,restaurant_name,cuisine_type):
self.restaurant_name=restaurant_name
self.cuisine_type=cuisine_type
self.number_served=0
class IceCreamStand(Restaurant):
def __init__(self,flavors):
super().__init__(restaurant_name,cuisine_type)
self.flavors=flavors
def show(self):
print(self.flavors)
f=['apple','orange','pear']
ice=IceCreamStand(f)
ice.show()
调用的时候就出错了,NameError: name 'restaurant_name' is not defined
在这之前就已经提示“未解析的引用”----》super().__init__(restaurant_name,cuisine_type)
这个是什么原因啊?
怎么解决呢?
哪位前辈帮忙一下啊
- class Restaurant:
- '''餐馆的描述'''
- def __init__(self,restaurant_name,cuisine_type):
- self.restaurant_name=restaurant_name
- self.cuisine_type=cuisine_type
- self.number_served=0
- class IceCreamStand(Restaurant):
- def __init__(self,restaurant_name,cuisine_type,flavors):
- super().__init__(restaurant_name,cuisine_type)
- self.flavors=flavors
- def show(self):
- print('店名:',self.restaurant_name)
- print('风格:',self.cuisine_type)
- print(self.flavors)
-
- f=['apple','orange','pear']
- ice=IceCreamStand('鱼C冰淇淋店','icecream',f)
- ice.show()
复制代码
你的代码貌似缩进有问题,不知道是因为你没有用过代码模式发帖还是因为你本身缩进就错了
2构造方法要把restaurant_name,cuisine_type这两个参数加上,下边实例化的时候也要带对应的参数
|
|