Assigning variables - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Assigning variables (/thread-26276.html) |
Assigning variables - Godserena - Apr-26-2020 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" RE: Assigning variables - DPaul - Apr-26-2020 Could you give an example of what you mean, so it becomes clearer. Normally you would assign numbers to variables, ... Paul RE: Assigning variables - Godserena - Apr-26-2020 (Apr-26-2020, 06:47 AM)DPaul Wrote: Could you give an example of what you mean, so it becomes clearer.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 RE: Assigning variables - ndc85430 - Apr-26-2020 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). RE: Assigning variables - buran - Apr-26-2020 (Apr-26-2020, 06:53 AM)Godserena Wrote: Hope this explains my problem morenope. 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. |