Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # adds the choice function from the random library
- from random import choice
- # Create two empty lists for teams A, B and C.
- teamA = []
- teamB = []
- teamC = []
- # Create a player list for the player group
- players = ['Harry', 'Hermione', 'Neville', 'Ginny', 'Peter','Kelly','Anne','Justin','Tim']
- print ("The players list for the pool of players are",int(len(players)))
- print ('Harry', 'Hermione', 'Neville', 'Ginny', 'Peter','Kelly','Anne','Justin','Tim')
- # Define the add_player_to_team function
- def add_player_to_team(team):
- # Pick a random players, add them to the team list and remove from players.
- player_picked = choice(players)
- # Add them to the team list
- team.append(player_picked)
- # Remove from the pool of players
- players.remove(player_picked)
- # Check if even number of players
- if len(players)%3 != 0:
- print("There are an even number of players, please add another team player to the list")
- else:
- # While there are players in the players list
- while len(players) != 0:
- # Call the add_player_to_team A function
- add_player_to_team(teamA)
- # Call the add_player_to_team B function
- add_player_to_team(teamB)
- # Call the add_player_to_team B function
- add_player_to_team(teamC)
- print ("The list of players in team A is: " + str(teamA))
- print ("The list of players in team B is: " + str(teamB))
- print ("The list of players in team C is: " + str(teamC))
- print ("The players list now is empty: " + str(players))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement