I am trying to create a text-based rpg game in python for learning purposes. I have a problem with function to increase player attributes.
My player character class code:
class Hero:
def __init__(self, Hstrength, Hdexterity, Hendurance, Hmagic, Hname, Hlocation):
self.level = 1
self.xp_needed = 100
self.attribute_points = 0
self.strength = Hstrength
self.dexterity = Hdexterity
self.endurance = Hendurance
self.magic = Hmagic
self.name = Hname
self.location = Hlocation
And a function I came up with to let player improve attributes (defined in another file):
def train(character):
if (character.attribute_points > 0):
character_attributes = {
"str": character.strength,
"dex": character.dexterity,
"end": character.endurance,
"mag": character.magic
}
print("Which attribute you want to train?")
for attribute in character_attributes:
print(attribute)
a = input(">>")
if a in character_attributes:
character_attributes[a] += 1
character.attribute_points -= 1
print(f"Your {a} is now {character_attributes[a]}")
else:
print("Invalid attribute")
else:
print("Not enough attribute points")
But it does not change the value of attribute, just prints value bigger by one than the attribute.
How can I make this work, or let the player choose which attribute to improve and then increment it other way?