0

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?

1
  • 1
    You could create a list of lists, where each sublist will hold data for each player. But you need to elaborate more and provide some sample code in order to fully address your problem. Commented Mar 10, 2019 at 14:35

1 Answer 1

1

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'})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.