Advertisement
Antypas

Choose two teams

Apr 11th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. #Adding players to different teams
  2. from random import choice
  3.  
  4. teamA = []
  5. teamB = []    # Create two empty lists for teams A and B
  6.  
  7. players = ['Harry', 'Hermione', 'Neville', 'Ginny', 'Myself']
  8.  
  9. def add_player_to_team(team):
  10.     player_picked = choice(players)
  11.     team.append(player_picked)
  12.     players.remove(player_picked)
  13.    
  14. # Add a player to each team
  15. for index in range(len(players)//2*2):
  16.     if index%2 == 0:
  17.         add_player_to_team(teamA)
  18.     elif index%2 == 1:
  19.         add_player_to_team(teamB)
  20.  
  21. print("teamA ",teamA)
  22. print("teamB ",teamB)
  23. print("players, odd fellow out of luck ", players)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement