Advertisement
GCK

GCK/ team_maker function

GCK
Sep 25th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. import random
  2. from random import choice, randint, shuffle
  3.  
  4. print("Hello I'm gigi your bot, let's play a team maker game")
  5. team1= []
  6. team2= []
  7. players=['Harry','Hermione','Neville','Ginny']
  8. reserve_list=[]
  9. total_number_of_players=len(players)
  10. half_team=len(players)/2
  11. print("My list has "+ str(total_number_of_players) + " players")
  12.  
  13. """players_parity counts the number of players in the list and if uneven select a reserve player who
  14. will not be yet in a team
  15. """
  16. def players_parity():
  17.    
  18.     if total_number_of_players % 2==0:
  19.         print("all players will play")
  20.     else:
  21.         print("Number of players is uneven, one is randomly added to the reserve list and will play later")
  22.         reserve_player=choice(players)
  23.         reserve_list.append(reserve_player)
  24.         players.remove(reserve_player)
  25.     return players,len(reserve_list)
  26.          
  27.  
  28. """add_player_randomly_to_team(team) will add one player randomly selected to a team
  29. """      
  30. def add_player_randomly_to_team(team):
  31.     mypicked=choice(players)
  32.     team.append(mypicked)
  33.     players.remove(mypicked)
  34.     return team,players
  35.  
  36. """add_player_randomly_to_random_team() will add one random player to a random choice of team
  37. """    
  38. def add_player_randomly_to_random_team():
  39.     random_team=randint(0,1)
  40.    
  41.  #  for i in players: and
  42.     while  len(players)!=0:
  43.         if random_team==0 and len(team1)!=half_team:
  44.            add_player_randomly_to_team(team1)
  45.         elif random_team==1 and len(team2)!=half_team:
  46.            add_player_randomly_to_team(team2)
  47.         elif random_team==0 and len(team1)==half_team:
  48.            add_player_randomly_to_team(team2)
  49.         elif random_team==1 and len(team2)==half_team:
  50.            add_player_randomly_to_team(team1)
  51.     return team1, team2, len(players)
  52.  
  53. players,reserve_list_size=players_parity()
  54. print(players)
  55. team1, team2, players_left_size=add_player_randomly_to_random_team()
  56. print("Team 1 is "+ str(team1))
  57. print("Team 2 is "+ str(team2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement