Apr-12-2017, 05:21 PM
How do I fix this? (PY Latest version)
File "classes_01.py", line 11, in <module>
print (bs.health)
AttributeError: type object 'Blacksmith' has no attribute 'health'
Another one I got is this
File "magegame.py", line 1, in <module>
class Mage:
File "magegame.py", line 25, in Mage
David.health -= 50
AttributeError: 'function' object has no attribute 'health'
class Character(object): def __init__(self): self.health = 100 class Blacksmith(Character): def __init__(self): super(Blacksmith, self).__init__() bs = Blacksmith print (bs.health)Here's the error:
File "classes_01.py", line 11, in <module>
print (bs.health)
AttributeError: type object 'Blacksmith' has no attribute 'health'
Another one I got is this
class Mage: ''' A mage that visited a shady magic shop ''' def David(David,health,mana): David = Mage("David") David.health = 100 David.mana = 90 iBuy = input("Shady seller: What would you like to buy? \n\nApple \n\nDagger \n\nHealth potion \n\nMana potion \n\n ") if (iBuy == 'Apple'): print("\nThe apple was posionous! \nThe seller tricked me!") David.health -= 90 print("-The mage puked-" "\nI knew I couldn't trust him!") elif (iBuy == 'Dagger'): print("2 Days later") myWeapon = input('A thief broke in your house, because he wasnt quiet enough, you caught him. \n\nWhich weapon would you use to fight him? : \n\nStaff \n\nDagger \n ') if (myWeapon == 'Dagger'): print ('The dagger the shady shop seller gave you broke!') David.health -= 50 print(David.health) elif (myWeapon == 'Staff'): print("You beat the filthy thief, you selled his loot to buy a health potion") David.health +10 print (David.health) elif (iBuy == 'Health potion'): David.health +=5 print("The potion was weak, yet added bonus HP \n\nThe potion was really expensive considering the health it gave.") elif (iBuy == 'Mana potion'): David.mana += 20 print ("The mana potion was the only reliable thing to buy in this damn shop!") print (David.mana)The ERROR:
File "magegame.py", line 1, in <module>
class Mage:
File "magegame.py", line 25, in Mage
David.health -= 50
AttributeError: 'function' object has no attribute 'health'