Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Adding players to different teams
- # Suggested Alternative 2:
- '''
- Iterate through the list of players, and for each player,
- randomly assign them to a team. You’ll need to make sure
- that you don’t end up with uneven teams!
- '''
- from random import choice
- teamA = []
- teamB = [] # Create two empty lists for teams A and B
- team_list = [teamA, teamB]
- players = ['Harry', 'Hermione', 'Neville', 'Ginny', 'Myself']
- #players = ['Harry', 'Hermione', 'Neville', 'Ginny']
- #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']
- def assign_player_to_team(player):
- team_picked = choice(team_list)
- team_picked.append(player)
- # players.remove(player)
- for player in players:
- if len(teamA) < len(players)//2 and len(teamB) < len(players)//2:
- assign_player_to_team(player)
- elif len(teamA) > len(teamB):
- teamB.append(player)
- elif len(teamA) < len(teamB):
- teamA.append(player)
- elif len(teamA) == len(teamB):
- assign_player_to_team(player)
- print("teamA ",teamA)
- print("teamB ",teamB)
- print("Players ", players)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement