I'm creating some simple code for my Intro to Python class. However, I keep recieving an attribute error on line 12: "AttributeError: 'int' object has no attribute 'strengthPts'". Here is my code:
class superhero:
def __init__(self, name = "", strengthPts = 0, motto = "", strength = ""):
self.name = name
self.strengthPts = int(strengthPts)
self.motto = motto
self.strenght = strength
def addStrengthPts(self, points):
self.strengthPts = self.strengthPts + points
def main():
s = superhero("Señor Cement", 0, "These streets won\'t stop me!", "creating cement from matter around him and using it to halt villains.")
superhero.addStrengthPts(0,5)
print("Today on Super of the Week, we present to you" + s.name + "After taking down a villain," + s.name + "gained" + str(s.strengthPts) + "points! With their power of" + s.strength + "and the awesome motto,\"" + s.motto + " you\'ll definitely want to give their comic a read!")
main()
As you can see, I assigned the class function superhero to s in line 10, believing that the problem might have been that I was refrencing the class incorrectly. Additionally, I've tried reassigning strengthPts as an integer, believing python may not be reading the perameter as one. However, none of this has worked, and I just keep recieving the same error. Any ideas?
s
when calling the method addStrengthPts
to get furtherself.strengthPts
__init__
). I guess you meant self.strength
Hope this helps