Advertisement
timber101

PlayersSplitterUsingChoiceAndWhileLoop

Dec 24th, 2020
975
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None
  1. from random import choice # bring in the choice function from random library
  2.  
  3. teamA_picked_players = []
  4. teamB_picked_players = []
  5.  
  6. my_players_list = ["Pete", "dave", "Simon", "Gerald", "Clive"]
  7.  
  8.  
  9. def add_player_to_team(team):
  10.     picked = choice(my_players_list)
  11.     team.append(picked)
  12.     my_players_list.remove(picked)
  13.    
  14. while len(my_players_list) > 0:
  15.     add_player_to_team(teamA_picked_players)
  16.     try:
  17.         add_player_to_team(teamB_picked_players)
  18.     except:
  19.         pass
  20.  
  21.  
  22. print(f"Team A {teamA_picked_players} and has {len(teamA_picked_players)} players")
  23. print(f"Team B {teamB_picked_players} and has {len(teamB_picked_players)} players")
  24. print(my_players_list)
  25.  
  26.  
Advertisement
RAW Paste Data Copied
Advertisement