零基础入门python:038讲类和对象,继承
本帖最后由 一条胖咸鱼鸭 于 2021-1-26 16:14 编辑按照课程的代码,运行出来,在实例化的时候报错了,小白,不太清楚是为什么,求解答
输入:
fish = Fish()
之后报错:
TypeError: randint() missing 1 required positional argument: 'b'
代码如下:
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 Garp(Fish):
pass
class Salmon(Fish):
pass
class Shark(Fish):
def __init__(self):
self.hungry = True
def eat(self):
if self.hungry:
print('吃货的梦想就是天天有的吃!')
else:
print('太撑了,吃不下了!')
页:
[1]