from random import choice players = [] # a list of player names file = open(r'D:\codeclub\players.txt', 'r') players = file.read().splitlines() file.close() team_A = [] team_B = [] team_C = [] team_names = [] # make a list called team_names file = open(r'D:\codeclub\teamnames.txt', 'r') # Open the team_names.txt file team_names = file.read().splitlines() # add lines from file into the list file.close() team_name_A = choice(team_names) team_names.remove(team_name_A) team_name_B = choice(team_names) team_names.remove(team_name_B) team_name_C = choice(team_names) while len(players) > 0: player_A = choice(players) team_A.append(player_A) players.remove(player_A) if players == []: # stop if Team A just took the last player break player_B = choice(players) team_B.append(player_B) players.remove(player_B) if players == []: break player_C = choice(players) team_C.append(player_C) players.remove(player_C) print(f"Team:{team_name_A}") print(f"Players:{team_A}") print() print(f"Team:{team_name_B}") print(f"Players:{team_B}") print() print(f"Team:{team_name_C}") print(f"Players:{team_C}")