Reputation: 35
For a school project we have to write a mini game. I got stuck when I tried to create new variables in a loop. I wrote a code where the user has to give the number of the players, and the Idea was to create new variables in a loop for each player. My question would be 1st : Is it even possible? 2nd : I want to store more information in a variable ( weapon, vest etc...) , so should I prefer using dictionary?
Upvotes: 0
Views: 41
Reputation: 1628
1st: Make a list, and use subsequent elements of that list. You can't create a variable with the same name twice.
2nd: I would go with a dictionary.
E.G.:
playerdata= []
for player in numplayers:
playerdata.append({'playerID':player, 'weapon':'bow'})
Upvotes: 1