Advertisement
brendan-stanford

team_choice_v3

Aug 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. from random import choice
  2.  
  3. '''
  4. Create an empty list for teams and another for player names, then get user input for number of teams and player names,
  5. and determine how many players will be on each team by dividing the number of players by the number of teams and rounding into an integer
  6. '''
  7.  
  8. n_teams = int(input("Number of teams:"))
  9. teams = []
  10. for i in range(n_teams):
  11. teams.append([])
  12.  
  13. n_players = int(input("Number of players:"))
  14. players = []
  15. for i in range(n_players):
  16. players.append(input("Player number " + str(i + 1) + ":"))
  17.  
  18. t_size = int((len(players)/len(teams)))
  19. print("Team size is " + str(t_size) + "!")
  20.  
  21. #main picking function chooses a player and adds them to current team list
  22. def play_picking(current_team, p_list):
  23. player = choice(p_list)
  24. current_team.append(player)
  25. p_list.remove(player)
  26.  
  27. #Build team roster based on number of lists
  28. def make_roster(tlist):
  29.  
  30. #iterate through each team in the list and build their roster
  31. for i in tlist:
  32.  
  33. #make the first player choice automatically so (len(i) % tisize) is not 0 initally
  34. play_picking(i, players)
  35.  
  36. #continue adding players until the appropriate t_size is reached
  37. while len(i) % t_size > 0:
  38. play_picking(i, players)
  39.  
  40. #Finally, any leftover players should be assigned to the first available team
  41. count = 0
  42. while players != []:
  43. print("Leftover player assigned to first available group!")
  44. play_picking(teams[count], players)
  45. count += 1
  46.  
  47. #run player picking function and print teams
  48. make_roster(teams)
  49. print players
  50. print teams
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement