Build a Game Character Stats Tracker - Build a Game Character Stats Tracker

Tell us what’s happening:

class GameCharacter:
def init(self,name):
self._name=‘Kratos’
self._level=1
self._health=100
self._mana=50
@property
def name(self):
return self._name
@property
def health(self):
return self._health
@health.setter
def health(self,health):
if health<0:
self._health=0
elif health>100:
self._health=100
else:
self._health=health
@property
def mana(self):

Your code so far

class GameCharacter:
    def __init__(self,name):
        self._name='Kratos'
        self._level=1
        self._health=100
        self._mana=50
    @property
    def name(self):
        return self._name
    @property
    def health(self):
        return self._health
    @health.setter
    def health(self,health):
        if health<0:
            self._health=0
        elif health>100:
            self._health=100
        else:
            self._health=health
    @property
    def mana(self):
        return self._mana
    @mana.setter
    def mana(self,mana):
        if mana<0:
            self._mana=0
        elif mana>50:
            self._mana=50
        else:
            self._mana=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):
         return (f"Name: {self.name}\n"
         f"Level: {self.level}\n"
         f"Health: {self.health}\n"
         f"Mana: {self.mana}")      
hero=GameCharacter('Kratos')
print(hero)
hero.health-=30
hero.mana-=10
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

Github Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-game-character-stats/68cabc534d2e741f33a3fe1d.md at main · freeCodeCamp/freeCodeCamp · GitHub

Tell us what’s happening:

What is wrong with code
class GameCharacter:
def init(self,name):
self._name=‘Kratos’
self._level=1
self._health=100
self._mana=50
@property
def name(self):
return self._name
@property
def health(self):
return self._health
@health.setterhealth.setter
def health(self,health):
if health<0:
self._health=0
elif health>100:
self._health=100
else:
self._health=health
@prop

Your code so far

class GameCharacter:
    def __init__(self,name):
        self._name='Kratos'
        self._level=1
        self._health=100
        self._mana=50
    @property
    def name(self):
        return self._name
    @property
    def health(self):
        return self._health
    @health.setter
    def health(self,health):
        if health<0:
            self._health=0
        elif health>100:
            self._health=100
        else:
            self._health=health
    @property
    def mana(self):
        return self._mana
    @mana.setter
    def mana(self,mana):
        if mana<0:
            self._mana=0
        elif mana>50:
            self._mana=50
        else:
            self._mana=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):
        return f"""Name: {self.name}
Level: {self.level}
Health: {self.health}
Mana: {self.mana}"""
              
hero=GameCharacter('Kratos')
print(hero)
hero.health-=30
hero.mana-=10
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

Github Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-game-character-stats/68cabc534d2e741f33a3fe1d.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @arti.patel09 :waving_hand:

Here, there is one single line that blocks all of your code. You hard coded in the __init__ :

Here, how can you change that if I want my character to have another name ?

Please do not create duplicate topics for the same challenge/project question(s). If you need more help then respond back to the original topic you created with your follow up questions and/or your updated code and question.

The duplicate topic has been unlisted.

Thank you.