Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Adding players to different teams
- # Suggested Alternative 3:
- '''
- Work out the number of players needed in one team,
- and use the sample function to randomly pick that
- number of players from the list. Then add the
- rest of the players to the second team.
- '''
- from random import sample
- teamA = []
- teamB = [] # Create two empty lists for teams A and B
- players = ['Harry', 'Hermione', 'Neville', 'Ginny', 'Myself']
- #players = ['Harry', 'Ginny']
- #players = ['Harry']
- #players = []
- #players = ['A', 'B', 'C', 'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R']
- team_size = len(players)//2
- my_sample = sample(players, team_size)
- teamA = teamA + my_sample
- for player in teamA:
- players.remove(player)
- teamB = teamB + players
- for player in teamB:
- players.remove(player)
- print("teamA ",teamA)
- print("teamB ",teamB)
- print("Players ", players)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement