Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import random
  2.  
  3. players = ['Harry', 'Hermione', 'Neville', 'Ginny']
  4.  
  5. teamA = []
  6. teamB = []
  7.  
  8. def add_players_to_team():
  9. team_players = len(players)/2
  10.  
  11. while len(players) > 0:
  12. for player in players:
  13. team = random.randint(0,1)
  14. if team == 0 and len(teamA) < team_players:
  15. teamA.append(player)
  16. players.remove(player)
  17. elif team == 1 and len(teamB) < team_players:
  18. teamB.append(player)
  19. players.remove(player)
  20.  
  21. print('Team A = ', teamA)
  22. print('Team B = ', teamB)
  23. print('Players = ', players)
  24.  
  25. if len(players) % 2 == 0 and len(players) > 0:
  26. add_players_to_team()
  27. else:
  28. print("\nThe player list can't be split between two teams")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement