python - Using a variable inside another variable -



python - Using a variable inside another variable -

this question has reply here:

how do variable variables in python? 8 answers

what trying create user enters name, programme takes that, adds word move , grabs set named *name*move.

here code far, want within **:

fredmove = set(["move1","move2","move3","move4"]) #different info joemove = set(["move","move","move3","move4"]) #for each name chrismove = set(["move1","move2","move3","move4"]) #this timmove = set(["move1","move2","move3","move4"]) #easier write out #i have many more lists, name = input("what name looking for? ").lower def movechecking(move1,move2,move3,move4,name): if (move1 not in *name*moves): print("move 1 not found!") if (move2 not in *name*moves): print("move 2 not found!") if (move3 not in *name*moves): print("move 3 not found!") if (move4 not in *name*moves): print("move 4 not found!") move1 = input("enter move 1 = ") move2 = input("enter move 2 = ") move3 = input("enter move 3 = ") move4 = input("enter move 4 = ") movechecking(move1,move2,move3,move4,name)

any way want in way lets me avoid creating movechecking() every person's name?

use dictionary.

moves = { "fred": set(["move1","move2","move3","move4"]) "joe": set(["move1","move2","move3","move4"]) "chris": set(["move1","move2","move3","move4"]) "tim": set(["move1","move2","move3","move4"]) } name = input("what name looking for?") in range(1, 5): move = input("enter move {} = ".format(i)) if move not in moves[name]: print("move {} not found!".format(i))

python variables

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -