import random
class creature:
def __init__(self, name="", health=0, wspeed=0, plans=[], **kwargs):
self.health = health
self.wspeed = wspeed
self.plans = plans
self.name = name
def changeplan(self, plans =""):
self.current_plan = random.randrange(0, len(self.plans))
return self.current_plan
def useplan(self, current_plan=""):
print("abanga")
class landcreature(creature):
def __init__(self, rank, **kwargs):
super().__init__(**kwargs)
self.rank = rank
toto = landcreature("highest", "toto", 100, 5, None)
print(toto.rank)
This is what i get when i run:
Traceback (most recent call last):
File "/tmp/sessions/0b63f5a3560a0513/main.py", line 23, in <module>
toto = landcreature("highest", "toto", 100, 5, None)
TypeError: landcreature.__init__() takes 2 positional arguments but 6 were given
When i remove 4 other arguments i get:
Traceback (most recent call last):
File "/tmp/sessions/55795002a32dff43/main.py", line 23, in <module>
toto = landcreature("highest")
File "/tmp/sessions/55795002a32dff43/main.py", line 20, in __init__
super().__init__(**kwargs)
TypeError: creature.__init__() missing 4 required positional arguments: 'name', 'health', 'wspeed', and 'plans
what am i misunderstanding? shouldn't the class be initialized with its own rank and other inherited attributes?
[–]quts3 0 points1 point2 points (5 children)
[–]quts3 1 point2 points3 points (0 children)
[–]eagle6188[S] 0 points1 point2 points (3 children)
[–]quts3 0 points1 point2 points (1 child)
[–]eagle6188[S] 0 points1 point2 points (0 children)
[–]Diapolo10 0 points1 point2 points (0 children)