I am trying to add multiple integers from a class in python however it comes up with the error:
Traceback (most recent call last): File "G:/documents/Computing/Python/Fighter Game.py", line 53, in if player.health() + player.strength() + player.defence() + player.speed() == 350: TypeError: 'int' object is not callable
The code for the class is:
class Fighter:
name = "Not Set"
alignment = "Not Set" #good / bad
health = 0
strength = 0
defence = 0
speed = 0
def name(self):
return self.name
def alignment(self):
return self.alignment
def health(self):
return self.health
def strength(self):
return self.strength
def defence(self):
return self.defence
def speed(self):
return self.speed
def set_name(self, new_name):
self.name = new_name
def set_alignment(self, new_alignment):
self.alignment = new_alignment
def set_health(self, new_health):
self.health = new_health
def set_strength(self, new_strength):
self.strength = new_strength
def set_defence(self, new_defence):
self.defence = new_defence
def set_speed(self, new_speed):
self.speed = new_speed
and the code that throws up the error is:
player = Fighter()
while True:
player.set_name(input("Enter your name: "))
player.set_alignment("good")
player.set_health(int(input("Enter your health: ")))
player.set_strength(int(input("Enter your strength: ")))
player.set_defence(int(input("Enter your defence: ")))
player.set_speed(int(input("Enter your speed: ")))
if player.health() + player.strength() + player.defence() + player.speed() == 350:
print("Player setup complete.")
break
else:
print("Numerical player values must all add up to 350.")
Any help that could be given would be appreciated! :-)
.healthcan't be both a property and a method. You're overwriting the method with a number when youset_health.