Advertisement
Antypas

Choose team with sample

Apr 11th, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. # Adding players to different teams
  2. # Suggested Alternative 3:
  3. '''
  4. Work out the number of players needed in one team,
  5. and use the sample function to randomly pick that
  6. number of players from the list. Then add the
  7. rest of the players to the second team.
  8. '''
  9.  
  10. from random import sample
  11.  
  12. teamA = []
  13. teamB = []    # Create two empty lists for teams A and B
  14.  
  15. players = ['Harry', 'Hermione', 'Neville', 'Ginny', 'Myself']
  16. #players = ['Harry', 'Ginny']
  17. #players = ['Harry']
  18. #players = []
  19. #players = ['A', 'B', 'C', 'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R']
  20.  
  21. team_size = len(players)//2
  22. my_sample = sample(players, team_size)
  23. teamA = teamA + my_sample
  24. for player in teamA:
  25.     players.remove(player)
  26. teamB = teamB + players
  27. for player in teamB:
  28.     players.remove(player)
  29.  
  30.  
  31. print("teamA ",teamA)
  32. print("teamB ",teamB)
  33. print("Players ", players)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement