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
- players = ['Harry', 'Hermione', 'Neville', 'Ginny']
- # Function to add players to teams
- def add_player_to_team(team):
- player_picked = choice(players)
- team.append(player_picked)
- players.remove(player_picked)
- # count the players available
- num_of_players = sum(1 for num_of_players in players)
- # Test we have an even number of players
- if num_of_players % 2 != 0:
- # Odd number of players so can' pick teams
- print("Can't pick teams as odd number of players !")
- elif num_of_players == 0:
- print("No players to select from !")
- else:
- # Add a player to each team
- for player in range(0, num_of_players, 2):
- add_player_to_team(teamA)
- add_player_to_team(teamB)
- print("Team A is - {}".format(teamA))
- print("Team B is - {}".format(teamB))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement