I am trying to modify a variable based on user input. For example if the user wanted to change their strength variable they would type in "strength" and then that variable (tied to a player object so in this example player.strength
) would be reassigned the new value.
I have attempted using dictionaries to hold the variable name as this is what I've used to call functions/methods as well but after browsing here a bit have realized this will not work due to it being immutable.
My current attempt looks like this:
skill_dict = {"Swords": self.swords}
answer = input("Which skill would you like to be proficient in?")
skill_dict[answer] += 10
print(skill_dict[answer])
print(self.swords)
The output however shows that this not work with the dictionary value being changed to 10 while the actual variable value remaining unchanged.
Is there a way to do this?