By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,676 Members | 2,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,676 IT Pros & Developers. It's quick & easy.

Please help me

P: 5
Hi,

I want the program to ask how many players that is in the game, and then depending on what number you wrote it's going to ask for every players name.

I think there's something wrong in the for loop. How do I make it work??


def numberOfPlayers():
a = raw_input("How many players are you? ")

number = numberOfPlayers()



def players():

player = raw_input("Whats your name? ")

return player

for a in range (0, len(number)):
players()
Oct 3 '06 #1
Share this Question
Share on Google+
1 Reply


bartonc
Expert 5K+
P: 6,596
Expand|Select|Wrap|Line Numbers
  1.  
  2. def numberOfPlayers():
  3.     a = raw_input("How many players are you? ")
  4.     return int(a)
  5.  
  6.  
  7. player_list = []
  8. for a in range (number):
  9.     player_list.append(players())
  10.  
  11.  
or

Expand|Select|Wrap|Line Numbers
  1.  
  2. player_list = []
  3. def players(n):
  4.     for a in range (n):
  5.         player_list.append(raw_input("Whats your name? "))
  6.  
  7.  
  8. players(number)
  9.  
  10.  
Now you have a list and can refer to each name as
player_list[n]
where n is zero to number - 1
Oct 3 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.