Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- 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.
- You’ll need to import the sample function from the random library.
- The following code would set my_sample to be a list containing
- three random elements from the list my_list:
- from random import sample
- my_sample = sample(my_list,3)
- # Randomly select 3 items from my_list and creates my_sample
- """
- from random import sample
- teamA = [] # empty list for team A
- teamB = [] # do for team B
- players = ['A', 'B', 'C', 'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R']
- # to preserve my original players list appending each element to teamB
- for i in range(0, len(players)):
- teamB.append(players[i])
- def make_teams(noz):
- tempA = (sample(players,noz))
- for i in range(0,len(tempA)):
- teamA.append(tempA[i])
- #print(f"tempA {tempA}") for debugging
- #print(f"teamA {teamA}") for debugging
- #print(f"teamB {teamB}") for debugging
- #print(f"players {players}") for debugging
- teamB.remove(tempA[i])
- #print(f"teamB {teamB}") for debugging
- make_teams(2)
- print(f"teamA final {teamA} of length {len(teamA)}")
- print(f"teamB final {teamB} of length {len(teamB)}")
- print(f"players final {players} of length {len(players)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement