Hi just started coding and i am practicing some things but i bumped into something really strange. This is it:
class Hero:
def __init__(self,name,weapon):
self.name=name
self.health=100
self.weapon=weapon
if(weapon=='Sword'):
self.damage=50
elif(weapon=='Spear'):
self.damage=40
elif(weapon=='Bow'):
self.damage=40
elif(weapon=='Staff'):
self.damage=60
self.heal=20
def attack(self,a):
a.health-=self.damage
print(self.name,'attacked',a.name,'with a',self.weapon,'and dealt',self.damage,'damage')
if(a.health>0):
print(a.name,'has',a.health,'left')
else:
print(self.name,'killed',a.name)
def heal(self,a):
a.health+=self.heal
print(self.name,'healed',a.name,'with a',self.weapon,'and restored',self.heal,'health')
print(a.name,'has',a.health,'left')
As you can see i just made a class to practice and after that i added two guys:
Bob=Hero('Bob','Spear')
Gonzo=Hero('Gonzo','Sword')
After that i tried the 'attack' function i created and everything went just fine:
>>> Bob.attack(Gonzo)
'Bob attacked Gonzo with a Spear and dealt 40 damage
Gonzo has 60 left'
After that i tried the 'heal' function i created but his popped up:
>>> Bob.heal(Gonzo)
Traceback (most recent call last):
File "<pyshell#370>", line 1, in <module>
Bob.heal(Gonzo)
TypeError: 'int' object is not callable
I havent used 'heal' anywhere else so it cant be names overlaping(I checked). This is very strange because i designed the 'heal' and 'attack' functions to work exactly the same way but 'attack' works and'heal' doesnt. PLEASE HELP