Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import choice
- from random import shuffle
- from random import sample
- teamA = []
- teamB = [] # Create two empty lists for teams A and B
- my_players = [] # List to select arbitrary number of players
- my_teams = []
- #players = ['Harry', 'Isabel', 'Jack', 'Ginny'] # I had no idea the original list were Harry Potter characters until I read the comments :)
- 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']
- num_players = int(input("How many players? ")) # Error if number of players too large
- num_teams =int(input("How many teams? ")) # Error if number of teams < 2
- # Error if number of teams > half number of players
- # loop to create teams A-N
- if num_players % num_teams != 0:
- print("Warning - teams will not all have the same number of players")
- # proceed = bool(input("OK to proceed? [Y]/[N]"))
- shuffle(players)
- my_players = sample(players, num_players)
- # pick teamA
- teamA = sample(my_players, int(len(my_players)/num_teams))
- for player in teamA:
- my_players.remove(player)
- teamB = sample(my_players, int(len(my_players)/(num_teams-1))) #counter required
- for player in teamB:
- my_players.remove(player)
- # loop over lines 22-24 until all teams have members
- print(my_players)
- '''
- # using pop to pick last player from list
- def add_to_team(team):
- shuffle(players) # list is shuffled before each player is selected
- player_picked = players[-1]
- team.append(player_picked)
- players.pop(-1)
- while len(players):
- # Add a player to each team
- add_to_team(teamA)
- add_to_team(teamB)
- '''
- '''
- # picking random player from static list
- def add_player_to_team(team):
- player_picked = choice(players)
- team.append(player_picked)
- players.remove(player_picked)
- while len(players):
- # Add a player to each team
- add_player_to_team(teamA)
- add_player_to_team(teamB)
- '''
- print("teamA: ",(teamA))
- print("teamB: ",(teamB))
Advertisement
Add Comment
Please, Sign In to add comment