为了账号安全,请及时绑定邮箱和手机立即绑定

类的多重调用怎么报错,如下错误:

class person(object):

    def __init__(self,name,age,gender):

        self.name=name

        self.age=age

        self.gender=gender

class skillmixin(object):

    def __init__(self,skillname):

        self.skillname=skillname

        

class student(person):

    def __init__(self,name,age,gender,score):

       super(student,self).__init__(name,age,gender)

       self.score=score

class teacher(person):

    def __init__(self,name,age,gender,coures):

        super(teacher,self).__init__(name,age,gender)

        self.coures=coures

        

class basketballmixin(skillmixin):

    def __init__(self,skillname,basketballlevel):

        super(basketballmixin,self).__init__(skillname)

        self.basketballlevel=basketballlevel

class footballmixin(skillmixin):

    def __init__(self,skillname,footballlevel):

        super(footballmixin,self).__init__(skillname)

        self.footballlevel=footballlevel        


class studenthobby(student,basketballmixin):

    def __init__(self,skillname,basketballlevel):

        super(studenthobby,self).__init__(name,age,gender,score,skillname,basketballlevel)

        print('I am a student being good at playing basketball,my name is %s'%s,self.name,self.basktballlevel)

        

class teacherhobby(teacher,footballmixin):

    def __init__(self,skillname,footballlevel):

        super(teacherhobby,self).__init__(name,age,gender,coures,skillname,footballlevel)

        print('I am a teacher being good at playing football,my name is %s'%s,self.name,self.footballlevel)


s=student('liyawang',15,'female',90)

t=teacher('jake',48,'male','comprehensive')

sk=basketballmixin('basketball','junior')

tk=footballmixin('foottball','medium')

#sh=basketballmixin(sk,'junior')

#th=footballmixin(tk,'medium')

studenthobby(s,sk)

#teacherbobby(t,th)


正在回答

4 回答

class person(object):
    def __init__(self, name, age, gender):
        self.name = name
        self.age = age
        self.gender = gender

class skillmixin(object):
    def __init__(self, skillname):
        self.skillname = skillname

class student(person):
    def __init__(self, name, age, gender, score):
        super(student, self).__init__(name, age, gender)
        self.score = score

class teacher(person):
    def __init__(self, name, age, gender, coures):
        super(teacher, self).__init__(name, age, gender)
        self.coures = coures

class basketballmixin(skillmixin):
    def __init__(self, skillname, basketballlevel):
        super(basketballmixin, self).__init__(skillname)
        self.basketballlevel = basketballlevel

class footballmixin(skillmixin):
    def __init__(self, skillname, footballlevel):
        super(footballmixin, self).__init__(skillname)
        self.footballlevel = footballlevel

class studenthobby(student, basketballmixin):
    def __init__(self, name, age, gender, score,skillname, basketballlevel):
        super(studenthobby, self).__init__(name, age, gender, score)
        print('I am a student being good at playing basketball,my name is %s' % self.name)

class teacherhobby(teacher, footballmixin):
    def __init__(self, name, age, gender, coures,skillname, footballlevel):
        super(teacherhobby, self).__init__(name, age, gender, coures)
        print('I am a teacher being good at playing football,my name is %s' % self.name)

s = student('liyawang', 15, 'female', 90)
t = teacher('jake', 48, 'male', 'comprehensive')
sk = basketballmixin('basketball', 'junior')
tk = footballmixin('foottball', 'medium')
# sh=basketballmixin(sk,'junior')
# th=footballmixin(tk,'medium')
studenthobby(s.name,s.age,s.gender,s.score,sk.skillname,sk.basketballlevel)
# teacherbobby(t,th)


0 回复 有任何疑惑可以回复我~
class person(object):
    def __init__(self, name, age, gender):
        self.name = name
        self.age = age
        self.gender = gender

class skillmixin(object):
    def __init__(self, skillname):
        self.skillname = skillname

class student(person):
    def __init__(self, name, age, gender, score):
        super(student, self).__init__(name, age, gender)
        self.score = score

class teacher(person):
    def __init__(self, name, age, gender, coures):
        super(teacher, self).__init__(name, age, gender)
        self.coures = coures

class basketballmixin(skillmixin):
    def __init__(self, skillname, basketballlevel):
        super(basketballmixin, self).__init__(skillname)
        self.basketballlevel = basketballlevel

class footballmixin(skillmixin):
    def __init__(self, skillname, footballlevel):
        super(footballmixin, self).__init__(skillname)
        self.footballlevel = footballlevel

class studenthobby(student, basketballmixin):
    def __init__(self, name,age,gender,score,skillname, basketballlevel):
        student.__init__(self,name,age,gender,score)
        basketballmixin.__init__(self,skillname, basketballlevel)
        print('I am a student being good at playing %s,my name is %s' %(self.name,self.basketballlevel))

class teacherhobby(teacher, footballmixin):
    def __init__(self, name,age,gender,coures,skillname, footballlevel):
        teacher.__init__(self,name, age, gender, coures )
        footballmixin.__init__(self,skillname, footballlevel)
        print('I am a teacher being good at playing %s,my name is %s' % (self.name, self.footballlevel))

s = student('liyawang', 15, 'female', 90)
t = teacher('jake', 48, 'male', 'comprehensive')
sk = basketballmixin('basketball', 'junior')
tk = footballmixin('foottball', 'medium')
# studenthobby(s.name, s.gender,s.score,tk.skillname,sk.basketballlevel)
# studenthobby("小明",12,"gender",90,"skillname",1)
studenthobby(s.name,s.age,s.gender,s.score,sk.skillname,sk.basketballlevel)
# sh=basketballmixin(sk,'junior')
# th=footballmixin(tk,'medium')
# teacherbobby(t,th)


0 回复 有任何疑惑可以回复我~
#1

高飞的鱼

这个代码在我的编辑器里,朋友可以帮忙看看哪里不对吗?报错信息: Traceback (most recent call last): File "/Users/lihui/IdeaProjects/laern/Python j进阶/3章 类的继承.py", line 270, in <module> c=BasStudent.getskill() TypeError: getskill() missing 1 required positional argument: 'self'
2022-03-05 回复 有任何疑惑可以回复我~

请盆友答复,谢谢!

0 回复 有任何疑惑可以回复我~
ile "index.py", line 45, in 
    studenthobby(s,sk)
  File "index.py", line 31, in __init__
    super(studenthobby,self).__init__(name,age,gender,score,skillname,basketballlevel)
NameError: global name 'name' is not defined


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

类的多重调用怎么报错,如下错误:

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信