title: How to make a looping function switch between players?
body: <p>I'm trying to write a game of snakes and ladders in python and my function to make the players move along the board doesn't seem to work.
  I need to make my function loop round over and over until the game is won but I don't know how to make it restart the function with the <code>new_pos</code> value in place of the <code>current_pos</code> value. Also, when I try and run it, it says <code>current_pos</code> is not defined.</p>
  <p>Ideally though, I need the function to switch between <code>player_one</code> and <code>player_two</code> throughout the game. somebody suggested the function I've written as <code>player_turns</code>, but I don't know how to actually incorporate this into the code?</p>
  <pre><code>import time
  import random
  def roll_dice():
      dice_value = random.randint(1,6)
      print(&quot;Its a...&quot; + str(dice_value))
      return dice_value
  
  
  player_one = input(&quot;What is your name Player One?&quot; + &quot;\n&quot;)
  player_two = input(&quot;What is your name Player Two?&quot; + &quot;\n&quot;)
  print(&quot;\n&quot; + str(player_one) + &quot; Vs &quot; + str(player_two) + &quot;\n&quot; + &quot;Let's Play!&quot;)
  
  
  def player_turns(total_turns):
      if total_turns % 2 == 0:
          total_turns += 1
          return player_one
  
      else:
          return player_two
  
  def move_player(player):
      snake_squares = {26: 17, 40: 9, 43: 24, 67: 25, 75: 57, 82: 71, 98: 80}
      ladder_squares = {10: 40, 16: 38, 37: 46, 41: 52, 50: 68, 53: 73, 87: 97}
      print(&quot;Your turn, &quot; + str(player))
      input(str(player) + &quot; , type 'roll' to roll the dice&quot; + &quot;\n&quot;)
      obtained_dice = roll_dice()
      new_pos = current_pos + obtained_dice
      print(str(player) + &quot;, move to space &quot; + str(new_pos))
  
      if new_pos &lt; 100:
          if new_pos in snake_squares:
              print(&quot;Oh no! you have landed on a snake!&quot; + &quot;\n&quot; + &quot;You fall down the snake and land back on square {0}&quot;. format(snake_squares[new_pos]))
              new_pos = snake_squares[new_pos]
              return new_pos
  
          elif new_pos in ladder_squares:
              print(&quot;Hurray, you have landed on a ladder!&quot; + &quot;\n&quot; + &quot;Climb the ladder and move to square number {0}&quot;. format(ladder_squares[new_pos]))
              new_pos = ladder_squares[new_pos]
              return new_pos
  
      elif new_pos &gt;= 100:
              print(&quot;Congratulations, &quot; + str(player) + &quot;!&quot; + &quot;\n&quot; + &quot;You win!&quot;)
               print(&quot;Hope you enjoyed the game!&quot;)
  
  </code></pre>