Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import random
  2. from random import choice
  3. from random import shuffle
  4. from random import sample
  5. teams = ["red", "blue", "pink"]
  6. players = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n","q"]
  7. total = (len(players))//(len(teams))
  8.  
  9.  
  10. def calculate_size(teams, players): # will need to deal with odd number teams
  11. # Pick a player, add them to the team list and remove from players.
  12. shuffle(teams)
  13. shuffle(players)
  14. numteams = int(len(teams))
  15. numplayers = int(len (players)) #//numteams #return interger part only oddno?
  16. print(teams)
  17. print(players)
  18. return numplayers, numteams
  19.  
  20. def add_player_to_team(players, count, numplayers):
  21. team_list = []
  22. for member in range (total):
  23. player_picked = random.choice(players)
  24. team_list.append(player_picked)
  25. players.remove(player_picked)
  26. if numplayers == 0: #could run out of players in the loop
  27. break;
  28. else:
  29. numplayers = numplayers - 1
  30. return team_list, players, numplayers
  31.  
  32.  
  33. numplayers,numteams = calculate_size(teams, players)
  34. index = 0
  35. count = numteams + 1
  36. while numplayers > 0 and index < numteams:
  37. team_list, players, numplayers = add_player_to_team(players, count, numplayers)
  38. teams.append(team_list)
  39. index = index + 1
  40.  
  41. #for i in range (count):
  42. print(teams)
  43. print("***************")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement