SHARE
TWEET

Untitled

a guest Dec 8th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from random import choice # adds the choice function from the random library
  2.  
  3. # Create 2 empty team lists and players list for the pool of players
  4. teamA = []
  5. teamB = []
  6. players = ['Harry', 'Mark','Hermione', 'Neville', 'Ginny', 'Eric' , 'George' , 'Michael' ,'Stan' , "Brian" , "Derek" , 'Rory' , 'Nathan' ]
  7. # try with one player
  8. # players = ['Harry' ]
  9. # try with an odd number of players
  10. #players = ['A', 'B','C', 'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S']
  11.  
  12. # define the add_player_to_team function
  13. def add_player_to_team(team):
  14.     # Pick a player, add them to the team list and remove from players.
  15.     player_picked = choice(players)
  16.     team.append(player_picked)
  17.     players.remove(player_picked)
  18.  
  19. # Add a player to each team, copes with single nme or odd number of names
  20. while len(players):
  21.         add_player_to_team(teamA)
  22.         if len(players)>0:
  23.             add_player_to_team(teamB)
  24. print("Team A")
  25. print (teamA)
  26. print("TeamB")
  27. print (teamB)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top