title: How to Rectify While Loop for Tic-Tac-Toe Game on Python?
body: <pre><code>def display_board(board):
      print(board[7]+"|"+board[8]+"|"+board[9])
      print("-|-|-")
      print(board[4]+"|"+board[5]+"|"+board[6])
      print("-|-|-")
      print(board[1]+"|"+board[2]+"|"+board[3])
      print("-|-|-")   
  
  testing_board=[" "]*10
  display_board(testing_board)
  
  def player_input():
      marker=" "
      while marker !="x" or marker !="o":
          marker= input("player1 choose x,o: ")
  
          if marker=="o":
              return ("o","x")
          else:
              return ("x","o")
          break
  
  player_input()
  
  import random
  
  def first_move():
      if random.randint(0,1)==1:
          return "player 2"
      else:
          return "player 1"
  
  def handle_turn(board,marker,position):
      position=input("select a position from 1-9: ")
      position=int(position)
      board[position]=marker
  
  handle_turn(testing_board,"x",8)
  display_board(testing_board)
  
  def check_win(board, mark):
      return ((board[7]==mark and board[8]==mark and board[9]==mark)or
      (board[4]==mark and board[5]==mark and board[6]==mark)or
      (board[1]==mark and board[2]==mark and board[3]==mark)or
      (board[7]==mark and board[4]==mark and board[1]==mark)or
      (board[8]==mark and board[5]==mark and board[2]==mark)or
      (board[9]==mark and board[6]==mark and board[3]==mark)or
      (board[7]==mark and board[5]==mark and board[3]==mark)or
      (board[9]==mark and board[5]==mark and board[1]==mark))
  
  check_win(testing_board,"x")
  
  def space_free(board,position):
      return board[position]==" "
  
  def fullboardcheck(board):
      for i in range(1,10):
          if space_free(board, i):
              return False
      return True
  
  def player_choice(board):
      position = 0
  
      while position not in [1,2,3,4,5,6,7,8,9] or not space_free(board,position):
          return position
  
  #game start
  #board,marker,first player to go
  while True:
      theBoard = [' '] * 10
      player1_marker, player2_marker = player_input()
      turn = first_move()
      print (turn + " will go first")
  
     #game play 
      play_game = input('Are you ready to play? Enter Yes or No.')
  
      if play_game == "Yes":
          game_is_on = True
      else:
          game_is_on = False
  
      while game_is_on:
          #player1 turn
          if turn=="player 1":
              display_board(theBoard)
              position=player_choice(theBoard)
              handle_turn(theBoard,player1_marker,position)
  
              if check_win(theBoard,player1_marker):
                  display_board(theBoard)
                  print('Congratulations! You have won the game!')
                  game_is_on=False
              else:
                  if fullboardcheck(theBoard):
                      display_board(theBoard)
                      print('The game is a draw!')
                  else:
                      turn = 'player 2'
  
          else:
              display_board(theBoard)
              position = player_choice(theBoard)
              handle_turn(theBoard, player2_marker, position)
  
              if check_win(theBoard, player2_marker):
                  display_board(theBoard)
                  print('player 2 has won!')
                  game_is_on=False
  
              else:
                  if fullboardcheck(theBoard):
                      display_board(theBoard)
                      print('The game is a draw!')
                  else:
                      turn = 'player 1'
  </code></pre>
  
  <p>I am trying to build a tic-tac-toe game on Python. Above is the code I have written till now, and I am getting stuck at the below points.</p>
  
  <ol>
  <li>Player 1's first move isn't being registered</li>
  <li>Player 2's first move is declaring him to be the winner straightaway without any further moves from either player.</li>
  <li>My while loop isn't working to check whether all positions have been filled or not.</li>
  </ol>
  
  <p>I am new to Python, request some guidance on where I am going wrong.</p>