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
  Assigning a new value to variable uriel 1 1,568 Dec-04-2021, 02:59 PM
Last Post: Underscore
  assigning a variable :( gr3yali3n 0 1,287 Sep-22-2020, 09:02 PM
Last Post: gr3yali3n
  Where to put the global keyword when assigning variables outside a function? new_to_python 8 2,871 Feb-09-2020, 02:05 PM
Last Post: new_to_python
  Assigning a Variable Help MC2020 5 2,879 Jan-06-2020, 10:54 PM
Last Post: MC2020
  Assigning an item from a list xlev 1 1,428 Sep-27-2019, 04:42 PM
Last Post: Larz60+
  assigning index 3Pinter 6 2,946 Jan-18-2019, 10:07 PM
Last Post: nilamo
  Not adding and assigning? 00712411 7 4,059 Oct-10-2018, 07:11 PM
Last Post: volcano63
  Assigning iter_row value to variable ankey 8 8,943 Sep-24-2018, 03:51 PM
Last Post: ankey
  Assigning a new variable in a IF loop pythoneer 5 3,734 Mar-02-2018, 05:21 AM
Last Post: pythoneer
  Assigning to string slice michaeljhuman 1 2,723 Feb-08-2018, 12:57 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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