Python TypeError:不带参数

时间:2019-02-28 08:49:26

标签: python

我是python的新手,目前正在学习在线课程。我有以下代码(请参见下文),并且确实无法理解为什么收到以下错误消息:

Traceback (most recent call last):
    File blahblah, line 21, in <module>
      enemy1 = Enemy(50, 69)
  TypeError: Enemy() takes no arguments

Process finished with exit code 1

==

代码如下:

import random

class Enemy:
    HP = 200

    def _init_(self, atkl, atkh):
        self.atkl = atkl
        self.atkh = atkh


    def getAtk(self):
        print("atk is", self.atkl)

    def getHP(self):
        print("HP is", self.hp)

enemy1 = Enemy(50, 69)
enemy1.getAtk()
enemy1.getHP()

enemy2 = Enemy(75, 90)
enemy2.getAtk()
enemy2.getHP()

...

任何想法为什么我都会收到以下行的错误消息:敌人1 =敌人(50,69)

0 个答案:

没有答案