TypeError: attack() missing 1 required positional argument: ‘self’

You’re not instantiating your Enemy class. You are creating a new reference to the class itself. Then when you try and call a method, you are calling it without an instance, which is supposed to go into the self parameter of attack().

Change

enemy = Enemy

to

enemy = Enemy()

Also (as pointed out in by Kevin in the comments) your Enemy class should probably have an init method to initialise its fields. E.g.

class Enemy:
    def __init__(self):
        self.life = 3
    ...

Leave a Comment