|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
fish.move()
File "C:\Users\lenovo\Desktop\fish.py", line 9, in move
self.x -= 1
AttributeError: 'Fish' object has no attribute 'x'
>>>
亲们 有出现过这个问题的么,,,程序正常跑起来了,,在 fish =Fiche()
fich。move()报错了,我是3.7.0
我感觉 我们没啥问题啊,,,大家帮我看看吧,我用的3.7.0的
附我的联系源码,按照小甲鱼课程里面的。
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 :
pring("吃货的梦想就是天天有的吃")
self.hungry =False
else:
print("太撑了,吃不下了")
|
|