|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这段代码报错:输入
>>> pool=Pool(1,19)
>>> pool.print_num()
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
pool.print_num()
File "E:/python/test1.py", line 15, in print_num
print("水池里总共有乌龟%d只,小鱼%d条!"%(self.trutle.num,self.fish.num))
AttributeError: 'Pool' object has no attribute 'trutle'
>>>
源码如下:
class Trutle:
def __init__(self,x):
self.num=x
class Fish:
def __init__(self,x):
self.num=x
class Pool:
def __init__(self,x,y):
self.trurle=Trutle(x)
self.fish=Fish(y)
def print_num(self):
print("水池里总共有乌龟%d只,小鱼%d条!"%(self.trutle.num,self.fish.num))
class Trutle:
def __init__(self,x):
self.num=x
class Fish:
def __init__(self,x):
self.num=x
class Pool:
def __init__(self,x,y):
self.trurle=Trutle(x)
self.fish=Fish(y)
def print_num(self):
print("水池里总共有乌龟%d只,小鱼%d条!"%(self.trutle.num,self.fish.num))
我标红的地方应该改为 trutle
|
|