Advertisement
brendan-stanford

team_choice_v1

Aug 20th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 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. '''
  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.  
  19. #main function that takes team list and player list to build teams
  20. def player_pick(tlist, plist):
  21. #iterate through each team in the list and build their roster
  22. for i in tlist:
  23. #make the first player choice automatically so (len(i) % tisize) is not 0 initally
  24. player = choice(plist)
  25. i.append(player)
  26. plist.remove(player)
  27.  
  28. #continue adding players until the appropriate t_size is reached
  29. if len(i) % t_size > 0:
  30. player = choice(plist)
  31. i.append(player)
  32. plist.remove(player)
  33.  
  34. #put any leftover players on a random team
  35. team = choice(tlist)
  36. player = choice(plist)
  37. team.append(player)
  38. plist.remove(player)
  39.  
  40. #run player picking function and print teams
  41. player_pick(teams, players)
  42. print players
  43. print teams
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement