猫史档案馆


这段代码哪错了

用户:_Rise__Rise_查看:4 回复:10 评论:4 创建时间:2020-08-15T21:22:00


class Fruit:
    def __init__(self,color = '绿色'):
        Fruit.color = color
    def harvest(self,color):
        print('苹果是'+self.color+'的')
        print('苹果原来是'+Fruit.color+'的');
class Apple(Fruit):
    color = '红色'
    def __init__(self):
        print('我是苹果')
        super().__init__()
class Sapodilla(Fruit):
    def __init__(self):
        print('\n我是人参果')
        super().__init__(color)
    def harvest(self,color):
        print('水果是'+color+'的')
        print('水果原来是'+Fruit.color+'的');
apple = Apple()
apple.harvest(apple.color)
sapodilla = Sapodilla('白色')
sapodilla.harvest('金黄色')

提示是21行出错


回复

上一页1 页 / 共 1下一页
_Rise__Rise_

点赞0


评论


_Rise__Rise_

点赞0


评论


_Rise__Rise_

点赞0


评论


_Rise__Rise_

点赞0


评论


_Rise__Rise_

点赞0


评论


_Rise__Rise_

点赞0


评论


_Rise__Rise_

点赞0


评论


小星星『Jerry工作室』小星星『Jerry工作室』

用下积木模式emotion_喵喵

点赞0


评论


lsk666666lsk666666

给你改好了,注意人参果类的构造器里应该带上color参数!

class Fruit:
    def __init__(self,color = '绿色'):
        Fruit.color = color
    def harvest(self,color):
        print('苹果是'+self.color+'的')
        print('苹果原来是'+Fruit.color+'的');
class Apple(Fruit):
    color = '红色'
    def __init__(self):
        print('我是苹果')
        super().__init__()
class Sapodilla(Fruit):
    def __init__(self,color):
        print('\n我是人参果')
        super().__init__(color)
    def harvest(self,color):
        print('水果是'+color+'的')
        print('水果原来是'+Fruit.color+'的');
apple = Apple()
apple.harvest(apple.color)
sapodilla = Sapodilla('白色')
sapodilla.harvest('金黄色')

点赞0


评论


86135clc86135clc

class Sapodilla(Fruit):
    def __init__(self):
class Sapodilla(Fruit):
    def __init__(self,color):

点赞0


评论