|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random
class Fish:
def __int__(self):
self.x = random.randint(0,10)
self.y = random.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 __int__(self):
self.hungry = True
def eat(self):
if self.hungry:
print('天天有鱼吃')
self.hungry = False
else:
print('我吃饱了!')
运行:
>>> fish = Fish()
>>> fish.move()
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
fish.move()
File "C:/Users/Administrator/Desktop/小甲鱼/p11_2.py", line 9, in move
self.x -= 1
AttributeError: 'Fish' object has no attribute 'x'
这是什么原因啊
|
|