Advertisement
xavicano

Untitled

Aug 14th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. from random import choice
  2.  
  3. teamA = []
  4. teamB = []    # Create two empty lists for teams A and B
  5.  
  6. teamsN=['FCB','PSG','AJAX','MC','MU','CHE','TOT']
  7.  
  8.  
  9. players = ['Harry', 'Hermione', 'Neville', 'Ginny', 'Lionel', 'Xavi', 'Jordi', 'Jaume', 'Joan','Pere','Andreu','Lluis','Carles','A', 'B', 'C', 'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R']
  10.  
  11. def add_player_to_team(team):
  12.     if players:
  13.         player_picked = choice(players)
  14.         team.append(player_picked)
  15.         players.remove(player_picked)
  16.         return True
  17.     else:
  18.         return False
  19.    
  20. def make_team_of_nplayers(teamX, num_players):
  21.     while num_players>0:
  22.         if add_player_to_team(teamX)==False:
  23.             print("No players available")
  24.             return
  25.         else:
  26.             num_players-=1
  27.            
  28. def make_teams(teams, players):
  29.     nplayers=len(players)//len(teams)
  30.     #print("Players per team is ", nplayers)
  31.     #print(" teams =",len(teams))
  32.     #print(" players =",len(players))
  33.     for i in teams:
  34.         i=list()
  35.         #print(i,nplayers)
  36.         make_team_of_nplayers(i,nplayers)
  37.         print(i)
  38.    
  39. ## Add a player to each team
  40. #add_player_to_team(teamA)
  41. #add_player_to_team(teamB)
  42.  
  43. #print ("Team  A =", teamA)
  44. #print ("Team  B =", teamB)
  45.  
  46. ## Teams of nplayers
  47. #make_team_of_nplayers(teamA,4)
  48. #print ("Team  A =", teamA)
  49.  
  50. #make_team_of_nplayers(teamB,3)
  51. #print ("Team  B =", teamB)
  52.  
  53. ## N teams of nplayers
  54.  
  55. make_teams(teamsN, players)
  56. print(teamsN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement