Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import choice
- '''
- Create an empty list for teams and another for player names, then get user input for number of teams and player names,
- and determine how many players will be on each team by dividing the number of players by the number of teams and rounding into an integer
- '''
- n_teams = int(input("Number of teams:"))
- teams = []
- for i in range(n_teams):
- teams.append([])
- n_players = int(input("Number of players:"))
- players = []
- for i in range(n_players):
- players.append(input("Player number " + str(i + 1) + ":"))
- t_size = int((len(players)/len(teams)))
- print("Team size is " + str(t_size) + "!")
- #main picking function chooses a player and adds them to current team list
- def play_picking(current_team, p_list):
- player = choice(p_list)
- current_team.append(player)
- p_list.remove(player)
- #Build team roster based on number of lists
- def make_roster(tlist):
- #iterate through each team in the list and build their roster
- for i in tlist:
- #make the first player choice automatically so (len(i) % tisize) is not 0 initally
- play_picking(i, players)
- #continue adding players until the appropriate t_size is reached
- while len(i) % t_size > 0:
- play_picking(i, players)
- #Finally, any leftover players should be assigned to the first available team
- count = 0
- while players != []:
- print("Leftover player assigned to first available group!")
- play_picking(teams[count], players)
- count += 1
- #run player picking function and print teams
- make_roster(teams)
- print players
- print teams
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement