Jan-19-2022, 09:34 AM
A subclass needs to call the __init__() method(s) of its superclass(es) to so they can initialize their instance variables. In this case Player.__init__() does not call GenericPlayer.__init__(). Since GenericPlaier.__init__() was never called this code was never executed:
To call the superclass __init__() you should use the super().__init__(self) as recommended by bowlofred. Sometimes you will see this done using the superclass name explicitly.
self.hit = Trueself.hit is never assigned, so there is no "hit" attribute in player1.
To call the superclass __init__() you should use the super().__init__(self) as recommended by bowlofred. Sometimes you will see this done using the superclass name explicitly.
class Player(Generic_Player): def __init__(self, name): GenericPlayer.__init__(self) self.name = name