Tell us what’s happening:
i need help with the gamecharacter stats tracker, everytime i run tests it get an error
Your code so far
class GameCharacter:
def __init__(self, name):
self._name = name
self._health = 100
self._mana = 50
self._level = 1
@property
def name(self):
return self._name
@property
def health(self):
return self._health
@health.setter
def health(self, value):
if value < 0:
self._health = 0
elif value > 100:
self._health = 100
else:
self._health = value
@property
def mana(self):
return self._mana
@mana.setter
def mana(self, value):
if value < 0:
self._mana = 0
elif value > 50:
self._mana = 50
else:
self.mana = value
@property
def level(self):
return self._level
def level_up(self):
self._level += 1
self.health = 100
self.mana = 50
print(f"{self._name} leveled up to {self._level}!" )
def __str__(self):
return f"Name: {self._name}\nLevel: {self._level}\nHealth: {self._health}\nMana: {self._mana}"
hero = GameCharacter('Kratos')
print(hero)
hero.health -= 30
hero.mana -= 10
print(hero)
hero.level_up()
print(hero)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Challenge Information:
Build a Game Character Stats Tracker - Build a Game Character Stats Tracker