timpin

Untitled

Aug 29th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. from random import choice
  2. from random import shuffle
  3. from random import sample
  4.  
  5. teamA = []
  6. teamB = [] # Create two empty lists for teams A and B
  7. my_players = [] # List to select arbitrary number of players
  8. my_teams = []
  9.  
  10. #players = ['Harry', 'Isabel', 'Jack', 'Ginny'] # I had no idea the original list were Harry Potter characters until I read the comments :)
  11. players = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
  12.  
  13. num_players = int(input("How many players? ")) # Error if number of players too large
  14. num_teams =int(input("How many teams? ")) # Error if number of teams < 2
  15. # Error if number of teams > half number of players
  16. # loop to create teams A-N
  17. if num_players % num_teams != 0:
  18. print("Warning - teams will not all have the same number of players")
  19. # proceed = bool(input("OK to proceed? [Y]/[N]"))
  20. shuffle(players)
  21. my_players = sample(players, num_players)
  22. # pick teamA
  23. teamA = sample(my_players, int(len(my_players)/num_teams))
  24. for player in teamA:
  25. my_players.remove(player)
  26. teamB = sample(my_players, int(len(my_players)/(num_teams-1))) #counter required
  27. for player in teamB:
  28. my_players.remove(player)
  29. # loop over lines 22-24 until all teams have members
  30. print(my_players)
  31. '''
  32. # using pop to pick last player from list
  33. def add_to_team(team):
  34. shuffle(players) # list is shuffled before each player is selected
  35. player_picked = players[-1]
  36. team.append(player_picked)
  37. players.pop(-1)
  38.  
  39. while len(players):
  40. # Add a player to each team
  41. add_to_team(teamA)
  42. add_to_team(teamB)
  43. '''
  44. '''
  45. # picking random player from static list
  46. def add_player_to_team(team):
  47. player_picked = choice(players)
  48. team.append(player_picked)
  49. players.remove(player_picked)
  50.  
  51. while len(players):
  52. # Add a player to each team
  53. add_player_to_team(teamA)
  54. add_player_to_team(teamB)
  55. '''
  56. print("teamA: ",(teamA))
  57. print("teamB: ",(teamB))
Advertisement
Add Comment
Please, Sign In to add comment