import random players = ['Harry', 'Hermione', 'Neville', 'Ginny'] teamA = [] teamB = [] def add_players_to_team(): team_players = len(players)/2 while len(players) > 0: for player in players: team = random.randint(0,1) if team == 0 and len(teamA) < team_players: teamA.append(player) players.remove(player) elif team == 1 and len(teamB) < team_players: teamB.append(player) players.remove(player) print('Team A = ', teamA) print('Team B = ', teamB) print('Players = ', players) if len(players) % 2 == 0 and len(players) > 0: add_players_to_team() else: print("\nThe player list can't be split between two teams")