Advertisement
brendan-stanford

team_choice_v2

Aug 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. from random import choice
  2.  
  3. '''
  4. Create a list of empty lists for teams and a list of player names, then determine how many players
  5. will be on each team by dividing the number of players by the number of teams and rounding into an integer
  6. '''
  7. teams = [[],[],[],[]]
  8. players = ["Bob", "Joe", "Ty", "Cat", "Mike", "Sam", "Carl", "Jen", "Dave"]
  9. t_size = int((len(players)/len(teams)))
  10. print("Team size is " + str(t_size) + "!")
  11.  
  12. #main picking function chooses a player and adds them to current team list
  13. def play_picking(current_team, p_list):
  14. player = choice(p_list)
  15. current_team.append(player)
  16. p_list.remove(player)
  17.  
  18. #Build team roster
  19. def make_roster(tlist):
  20. #iterate through each team in the list and build their roster
  21. for i in tlist:
  22. #make the first player choice automatically so (len(i) % tisize) is not 0 initally
  23. play_picking(i, players)
  24.  
  25. #continue adding players until the appropriate t_size is reached
  26. if len(i) % t_size > 0:
  27. play_picking(i, players)
  28.  
  29. #leftover players added to random teams
  30. if teams != []:
  31. print("Leftover players will be assorted randomly!")
  32. team = choice(tlist)
  33. play_picking(team, players)
  34.  
  35. #run player picking function and print teams
  36. make_roster(teams)
  37. print players
  38. print teams
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement