class Turtle:
def init(self,x):
self.num = x
class Fish:
def init(self,x):
self.num = x
class Pool:
def init(self,x,y):
self.turtle = Turtle(x)
self.fish = Fish(y)
def print_num(self):
print ("本池塘共有%d只乌龟,有%d条鱼",(self.turtle.num,self.fish.num))
运行和报错:
pool=Pool(1,10)
Traceback (most recent call last):
File "", line 1, in
pool=Pool(1,10)
TypeError: Pool() takes no arguments
pool=Pool()
pool.print_num()
Traceback (most recent call last):
File "", line 1, in
pool.print_num()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\complexDemo.py", line 17, in print_num
print ("本池塘有%d只乌龟,有%d条鱼",(self.turtle.num,self.fish.num))
AttributeError: 'Pool' object has no attribute 'turtle'
ps:好烦啊,不知道什么原因,和源代码一模一样,查了很多教程都是这样没报错,为啥我的会报错,求大神指点下