Advertisement
ceiszele

players using pop

Dec 12th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. from random import *
  2. teamA=[]
  3. teamB=[] #create 2 empty lists for team A and B
  4. players = ["Tom","Dick","Harry","Nigel","Sid","Bill","Sam","Will","D","P","X","Z","Y"]
  5.  
  6.  
  7. print(players)
  8. shuffle(players)
  9. print(players)
  10.  
  11. def add_player_to_team(team):
  12. #shuffle(players)
  13. #remove a player from the list and add them to the team
  14. player_picked = players.pop(-1)
  15. team.append(player_picked)
  16. #players.remove(player_picked)
  17. #team = choice(teams)
  18. i = int(len(players)/2)
  19. for player in range(i):
  20. add_player_to_team(teamA)
  21. add_player_to_team(teamB)
  22. if len(players) == 1:
  23. add_player_to_team(teamA)
  24. else:
  25. print("teamA = "+str(teamA), "teamB = " +str(teamB))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement