Python Forum

Full Version: Assigning variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I want to assign variables to numbers dependent upon the user. What i mean is that if the user chooses there are three people then assign them "A","B"and "C" or if the user chooses there are 4 people then assigned as "A","B","C" and "D"
Could you give an example of what you mean, so it becomes clearer.
Normally you would assign numbers to variables, ...

Paul
(Apr-26-2020, 06:47 AM)DPaul Wrote: [ -> ]Could you give an example of what you mean, so it becomes clearer.
Normally you would assign numbers to variables, ...

Paul
So um im trying to write a program where i take input from the user to them number of players in a game. Now i want to assign every player an alphabet. Since im letting the user decide the number of players i want the program to assign the first player as "A" the second as "B" and so on...
Hope this explains my problem more
Don't try to do this using single variables. If you have a collection of things, use a collection (e.g. a list or a dict).
(Apr-26-2020, 06:53 AM)Godserena Wrote: [ -> ]Hope this explains my problem more
nope.
Are these supposed to be variable names (which will be terrible idea).
You should have a data structure like list or dict and store player instances there. If it's a dict, you can have letters(i.e. strings) as keys.