Hello coders I have a bit of an issue; Im trying to get used to code using OOP but I keep getting an, "Attribute error". I can't seem to find the error on my own. So if you see what the issue is, please let me know and I would be most grateful. My code is here: class Ninjutsu: def __init__ (self, colour, element, damage): self.colour = colour self.element = element self.damage = damage def lightning(self): print("Zaapp!!") print("Paralysis effect") class Fire(Ninjutsu): def fire(self): print("Pffff") print("Burn effect") bolt = Ninjutsu("Blue", "Lightning", "10 Damage points") print(bolt.damage) bolt.lightning() Fire_ball = Ninjutsu("Orange", "Fire", "9 Damage points") print(Fire_ball.damage) Fire_ball.fire()
10/25/2019 4:35:01 PMMars_96
4 AnswersNew Answer
Your Ninjutsu class doesn't have the fire method in it. Fire_ball is an instance of that class so Fire_ball.fire() gives an error (as that method doesn't exist). Simply change the statement to Fire_ball = Fire("Orange", "Fire", "9 Damaga points") so now Fire_ball is an instance of the Fire class and thus has that fire() method.
oooohhh, thank you very much russ, that makes a lot of sense haha :)
This community is so great! haha
Mars_96 Not a problem 👍