|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码:import random as r
class Fish:
def _init_(self):
self.x=r.randint(0,10)
self.y=r.randint(0,9)
def move(self):
self.x -=1
print('我的位置是:',self.x,self.y)
def eat(self):
print('我要吃饭啦!')
class Goldfish(Fish):
pass
class Carp(Fish):
pass
class Salmon(Fish):
pass
class Shark(Fish):
def _init_(self):
Fish._init_(self)
执行结果:>>> shark=Shark()
>>> shark.move()
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
shark.move()
File "C:\Users\xiaoqian\Desktop\爬虫.py", line 7, in move
self.x -=1
AttributeError: 'Shark' object has no attribute 'x'
>>>
好久没用python记不清了,抱歉
是你的init方法少了个_
是__init__
Fish和Shark都是少了
|
|