StudentBasketball的构造函数改怎么写?

来源:3-4 Python中的多态

yupanpan714

2021-10-23 14:01

# Enter a code

#encoding=utf-8

class Person(object):

    def __init__(name,gender):

        self.name=name

        self.gender=gender

        

    def who(self):

        return 'I'm a person,my name is %s' %s self.name

        

class Student(Person):

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

        super(Student,self).__init__(name,gender)

        self.score=score

        

    def who(self):

        return 'I'm a student,my score is %s' % self.score

        

class Teacher(Person):

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

        super(Teacher,self).__init__(name,gender)

        self.course=course

        

    def who(self):

        return 'I'm a Teacher,my course is %s' % self.course

        

        

class SkillMixin(objetc):

    def __init__(self,ball):

        self.ball=ball

        

    def skill(self):

        return 'I can play %s' % self.ball

        

class BasketballMixin(SkillMixin):

    def __init__(self,ball,basketball):

        super(BasketballMixin,self).__init__(ball)

        self.basketball=basketball

        

    def skill(self):

        return 'I can play %s' % self.basketball

        

class FootballMixin(SkillMixin):

    def __init__(self,ball,football):

        super(FootballMixin,self).__init__(ball)

        self.football=football

        

    def skill(self):

        return 'I can play %s' % self.football

        

class StudentBasketball(Student,BasketballMixin):

    def __init__(self,name,gender,score,skill):        #对吗

        super(StudentBasketball,self).__init__()        #不会写了


        


写回答 关注

1回答

  • ご沉默旭ご
    2021-10-26 22:47:21
    # Enter a code
    # encoding=utf-8
    class Person(object):
        def __init__(self, name, gender):
            self.name = name
            self.gender = gender
    
        def who(self):
            return "I'm a person, my name is %s" % self.name
    
    
    class Student(Person):
        def __init__(self, name, gender, score):
            super(Student, self).__init__(name, gender)
            self.score = score
    
        def who(self):
            return "I'm a student, my score is %s" % self.score
    
    
    class Teacher(Person):
        def __init__(self, name, gender, course):
            super(Teacher, self).__init__(name, gender)
            self.course = course
    
        def who(self):
            return "I'm a Teacher, my course is %s" % self.course
    
    
    class SkillMixin(object):
        def __init__(self, ball):
            self.ball = ball
    
        def skill(self):
            return 'I can play %s' % self.ball
    
    
    class StudentBasketball(Student, SkillMixin):
        def __init__(self, name, gender, score, ball):  # 对吗
            Student.__init__(self, name, gender, score)
            SkillMixin.__init__(self, ball)


Python3 进阶教程(新版)

学习函数式、模块和面向对象编程,掌握Python高级程序设计

41910 学习 · 236 问题

查看课程

相似问题