Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import choice
- teamA = []
- teamB = [] # Create two empty lists for teams A and B
- teamsN=['FCB','PSG','AJAX','MC','MU','CHE','TOT']
- players = ['Harry', 'Hermione', 'Neville', 'Ginny', 'Lionel', 'Xavi', 'Jordi', 'Jaume', 'Joan','Pere','Andreu','Lluis','Carles','A', 'B', 'C', 'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R']
- def add_player_to_team(team):
- if players:
- player_picked = choice(players)
- team.append(player_picked)
- players.remove(player_picked)
- return True
- else:
- return False
- def make_team_of_nplayers(teamX, num_players):
- while num_players>0:
- if add_player_to_team(teamX)==False:
- print("No players available")
- return
- else:
- num_players-=1
- def make_teams(teams, players):
- nplayers=len(players)//len(teams)
- #print("Players per team is ", nplayers)
- #print(" teams =",len(teams))
- #print(" players =",len(players))
- for i in teams:
- i=list()
- #print(i,nplayers)
- make_team_of_nplayers(i,nplayers)
- print(i)
- ## Add a player to each team
- #add_player_to_team(teamA)
- #add_player_to_team(teamB)
- #print ("Team A =", teamA)
- #print ("Team B =", teamB)
- ## Teams of nplayers
- #make_team_of_nplayers(teamA,4)
- #print ("Team A =", teamA)
- #make_team_of_nplayers(teamB,3)
- #print ("Team B =", teamB)
- ## N teams of nplayers
- make_teams(teamsN, players)
- print(teamsN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement