Tell us what’s happening:
In the ‘Build a Game character Stats Tracker’ Lab, I am failing 19. + 20. and likewise 29. + 30. for the mana equivalent.
I’ve tried to refresh the lesson and with if-elif-else - still not passing it.
What am I overlooking here? Please provide a hint. Much appreciated!
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, new_health):
if new_health < 0:
raise ValueError(f"'Health' amount can't be below 0")
self._health = 0
if new_health > 100:
raise ValueError(f"'100' is the maximum amount for Health")
self._health = 100
self._health = new_health
@property
def mana(self):
return self._mana
@mana.setter
def mana(self, new_mana):
if new_mana < 0:
raise ValueError(f"'Mana' amount can't be below 0")
self._mana = 0
if new_mana > 50:
raise ValueError(f"'50' is the maximum amount for Mana")
self._mana = 50
self._mana = new_mana
@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):
line = f"Name: {self.name}\n"
line += f"Level: {self.level}\n"
line += f"Health: {self.health}\n"
line += f"Mana: {self.mana}"
return line
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 (X11; Linux x86_64; rv:143.0) Gecko/20100101 Firefox/143.0
Challenge Information:
Build a Game Character Stats Tracker - Build a Game Character Stats Tracker