Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import choice#import the choice function from the random library
- from random import shuffle #imports the shuffle function from the random library which randomises the order of list
- from random import sample #imports the sample function from the random library which randomly select items in list
- #create an empty list
- teamA =[]
- teamB =[]
- players =['Alfie', 'Bob', 'Charlie', 'Doug', 'Eric', 'Fred', 'Gareth', 'Harry', 'Ian', 'Jack']
- shuffle(players) #shuffle names in list
- #create the add_player_to_team function
- def add_player_to_team(team):
- #pick a player, add them to the team list (A or B) and remove that player from the players list
- player_picked = choice(players)
- team.append(player_picked)
- players.remove(player_picked)
- add_player_to_team(teamA) #call the add_player_to_teamfunction once
- add_player_to_team(teamB)
- #a loop which adds players to the teams until the players list is empty
- while players!=[]:
- add_player_to_team(teamA)
- add_player_to_team(teamB)
- print(teamA)
- print(teamB)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement