I want to change the value of a variable that's inside another variable, this is the code I have so far:
person1tokens = 0
person2tokens = 0
token_price = 5
accounts = ["person1tokens","person2tokens"]
def add_tokens(person,amount):
if person in accounts:
cost = amount*token_price
print("You need to pay %d$" % (cost))
payment = int(input("Payment? "))
if payment != cost:
print("Please enter the right amount next time, nothing changed")
else:
--Help here--, change value of a the in the function specified account to <account> += amount
print("Added " + str(amount) + " tokens to account " + str(person) + ", your current balance is " + str(eval(person)"."))
else:
print("fail")
I basically want to change the value of person1tokens(for example) without knowing beforehand that I want to change that value, and I want to change that value where it says --Help here--. But the problem is that it is inside the person variable and I don't know how to get the program to "unpack" it from there. So for example if the user does as follows:
add_tokens("person1tokens",5)
You need to pay 25$
Payment? 25
Added 25 tokens to account person1tokens, your current balance is 25.
Any ideas?