Advertisement
TonyMo

2_5_teamsshufflepop.py

Mar 24th, 2021
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. # 2 5 teamsshufflepop.py
  2.  
  3. # With Thanks mainly to Natalie S
  4.  
  5. from random import shuffle
  6.  
  7. teamA = []  # Create two empty lists for teams A and B
  8. teamB = []
  9.  
  10. players = ['Afiki', 'Bozo', 'Ching', 'Don', 'Emmet', 'Fox', 'Shoes' ]
  11. #players = ['Afiki', 'Bozo', 'Ching', 'Don', 'Emmet', 'Fox']
  12. #players = ['Ching', 'Don']
  13. #players = ['Emmet']
  14. #players = []
  15. #players = ['A', 'B', 'C', 'D','E','F','G','H','I','J','K','L','M','N','O','P','Q'] #,'R'
  16.  
  17. shuffle(players)    # to shuffle players list Once only.
  18.  
  19. def add_player(team):
  20.     # shuffle(players)              # to shuffle players list every round
  21.     playerPicked = players.pop()    #pop item from list and assign to variable
  22.     team.append(playerPicked)   #add popped player to list
  23.  
  24. #number of times to repeat
  25. repeat = len(players)//2
  26. for i in range(repeat):
  27.     add_player(teamA)
  28.     add_player(teamB)
  29.  
  30. #Print out the teams
  31. print("Team A:", ', '.join(teamA))
  32. print("Team B:", ', '.join(teamB))
  33. if players:
  34.     print("Benched:", ', '.join(players))
  35.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement