Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assigning variables
#1
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"
Reply
#2
Could you give an example of what you mean, so it becomes clearer.
Normally you would assign numbers to variables, ...

Paul
Reply
#3
(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
Reply
#4
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).
Reply
#5
(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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Where to put the global keyword when assigning variables outside a function? new_to_python 8 1,205 Feb-09-2020, 02:05 PM
Last Post: new_to_python

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020