SHARE
TWEET

player_team

Drach Sep 19th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. # function choose player to team
  4. def ch_player(team,players):
  5.     how = len(players)
  6.     a = random.randint(0,how-1)
  7.     team.append(players[a])
  8.     players.pop(a)
  9.     return players, team
  10.    
  11. players = ["Dark","Simon","Joan","Jimmy","Tom","John","Gregory","Ed","Jane"]
  12.  
  13. team1 = []
  14. team2 = []
  15.  
  16. how = int(len(players)/2)
  17. for i in range(how):
  18.     players, team1 = ch_player(team1,players)
  19.     players, team2 = ch_player(team2,players)
  20.    
  21. #if number of players is odd the last player go to random team
  22. teams = ["team1","team2"]
  23. if (len(players) % 2) != 0 and teams[random.randint(0,1)] == "team1":
  24.     players, team1 = ch_player(team1,players)
  25. elif (len(players) % 2) != 0 :
  26.     players, team2 = ch_player(team2,players)
  27.  
  28. print(team1)
  29. print(team2)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top