Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from random import choice
- from random import shuffle
- from random import sample
- teams = ["red", "blue", "pink"]
- players = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n","q"]
- total = (len(players))//(len(teams))
- def calculate_size(teams, players): # will need to deal with odd number teams
- # Pick a player, add them to the team list and remove from players.
- shuffle(teams)
- shuffle(players)
- numteams = int(len(teams))
- numplayers = int(len (players)) #//numteams #return interger part only oddno?
- print(teams)
- print(players)
- return numplayers, numteams
- def add_player_to_team(players, count, numplayers):
- team_list = []
- for member in range (total):
- player_picked = random.choice(players)
- team_list.append(player_picked)
- players.remove(player_picked)
- if numplayers == 0: #could run out of players in the loop
- break;
- else:
- numplayers = numplayers - 1
- return team_list, players, numplayers
- numplayers,numteams = calculate_size(teams, players)
- index = 0
- count = numteams + 1
- while numplayers > 0 and index < numteams:
- team_list, players, numplayers = add_player_to_team(players, count, numplayers)
- teams.append(team_list)
- index = index + 1
- #for i in range (count):
- print(teams)
- print("***************")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement