|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random as r
class fish:
def _init_(self):
self.x = r.randint(0,10)
self.y = r.randint(0,10)
def move(self):
self.x -= 1
print('我的位置是:',self.x,self.y)
class Goldfish(fish):
pass
class Carp(fish):
pass
class Salmon(fish):
pass
class Shark(fish):
def _init_(self):
self.hungry = True
def eat(self):
if self.hungry:
print('吃货的梦想就是天天有的吃')
self.hungry = False
else:
print('太棒了,吃不下了~')
这是原代码,但是我给类一个变量名然后进行输出move内部函数的时候为什么会报错
Traceback (most recent call last):
File "C:/Users/Lenovo/Desktop/鱼.py", line 26, in <module>
a.move()
File "C:/Users/Lenovo/Desktop/鱼.py", line 7, in move
self.x -= 1
AttributeError: 'fish' object has no attribute 'x'
这是错误,应该怎么修正呢
用pycharm或vscode吧,这个书写方面的问题,它会自动提示你,提升你的编写效率。
|
|