Advertisement
elena_gancedo

One players-list for thre teams

Aug 9th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. # adds the choice function from the random library
  2. from random import choice
  3.  
  4. # Create two empty lists for teams A, B and C.
  5. teamA = []
  6. teamB = []
  7. teamC = []  
  8. # Create a player list for the player group
  9. players = ['Harry', 'Hermione', 'Neville', 'Ginny', 'Peter','Kelly','Anne','Justin','Tim']
  10.  
  11. print ("The players list for the pool of players are",int(len(players)))
  12. print ('Harry', 'Hermione', 'Neville', 'Ginny', 'Peter','Kelly','Anne','Justin','Tim')  
  13.  
  14. # Define the add_player_to_team function
  15. def add_player_to_team(team):
  16.     # Pick a random players, add them to the team list and remove from players.
  17.     player_picked = choice(players)
  18.     # Add them to the team list
  19.     team.append(player_picked)
  20.     # Remove from the pool of players
  21.     players.remove(player_picked)
  22.    
  23. # Check if even number of players
  24. if len(players)%3 != 0:
  25.     print("There are an even number of players, please add another team player to the list")
  26. else:
  27.     # While there are players in the players list
  28.     while len(players) != 0:
  29.         # Call the add_player_to_team A function      
  30.         add_player_to_team(teamA)
  31.         # Call the add_player_to_team B function
  32.         add_player_to_team(teamB)
  33.         # Call the add_player_to_team B function
  34.         add_player_to_team(teamC)
  35.    
  36. print ("The list of players in team A is: " + str(teamA))
  37. print ("The list of players in team B is: " + str(teamB))
  38. print ("The list of players in team C is: " + str(teamC))
  39.  
  40. print ("The players list now is empty: " + str(players))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement