Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from random import choice, randint, shuffle
- print("Hello I'm gigi your bot, let's play a team maker game")
- team1= []
- team2= []
- players=['Harry','Hermione','Neville','Ginny']
- reserve_list=[]
- total_number_of_players=len(players)
- half_team=len(players)/2
- print("My list has "+ str(total_number_of_players) + " players")
- """players_parity counts the number of players in the list and if uneven select a reserve player who
- will not be yet in a team
- """
- def players_parity():
- if total_number_of_players % 2==0:
- print("all players will play")
- else:
- print("Number of players is uneven, one is randomly added to the reserve list and will play later")
- reserve_player=choice(players)
- reserve_list.append(reserve_player)
- players.remove(reserve_player)
- return players,len(reserve_list)
- """add_player_randomlyshuffled_to_team(team) will add one player after shuffling and pop the last
- player from the list and add that player to a team
- """
- def add_player_randomlyshuffled_to_team(team):
- shuffle(players)
- team.append(players[-1])
- players.pop()
- return team,players
- """add_player_randomlyshuffled_to_team(team) will add one player after shuffling and pop the last
- player from the list and add that player to a team
- """
- def add_player_randomlyshuffled_to_random_team():
- random_team=randint(0,1)
- while len(players)!=0:
- if random_team==0 and len(team1)!=half_team:
- add_player_randomlyshuffled_to_team(team1)
- elif random_team==1 and len(team2)!=half_team:
- add_player_randomlyshuffled_to_team(team2)
- elif random_team==0 and len(team1)==half_team:
- add_player_randomlyshuffled_to_team(team2)
- elif random_team==1 and len(team2)==half_team:
- add_player_randomlyshuffled_to_team(team1)
- return team1, team2, len(players)
- players,reserve_list_size=players_parity()
- print(players)
- team1, team2, players_left_size=add_player_randomlyshuffled_to_random_team()
- print("Team 1 is "+ str(team1))
- print("Team 2 is "+ str(team2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement