我在python中有一个严重的输入错误,有什么想法要解决吗?

问题描述 投票:0回答:2

我在尝试编写游戏的过程中遇到了这个严重错误。目前,这只是骨头,我正在尝试为玩家战斗的敌人之一编码信息。

class Enemy():
    def __init__(self):
        super(). __init__ (
            self.name = "Goblin" +
            self.healthpoints = 12 + # on this line
            self.damage = 3)
    def isAlive(self):
        return self.hp > 0
python
2个回答
0
投票

self.name = "Goblin" +是语法错误。您没有在"Goblin"中添加任何内容。它抱怨后面的行的原因是它试图将self.healthpoints = 12添加到"Goblin",并且您无法添加赋值语句。

我认为您想做的是这样的:

    def __init__(self):
        self.name = "Goblin"
        self.healthpoints = 12
        self.damage = 3

0
投票

您是要这样做吗?

class Enemy():
    def __init__(self):
        self.name = "Goblin"
        self.healthpoints = 12
        self.damage = 3
        super().__init__(name=self.name, healthpoints=self.healthpoints, damage=self.damage)
    enter code here
    def isAlive(self):
        return self.hp > 0
    ```
© www.soinside.com 2019 - 2024. All rights reserved.