title: Python: Why would a function called within a while loop return something different than when called alone?
body: <p>I have a first function, move(x, y, u, v) that is used to move a piece from coordinates (x,y) to (u, v) in a board game.</p>
  
  <pre><code>some_Class():
      def move(self, x, y, u, v):
  
          self.x = x
          self.y = y
          self.u = u
          self.v = v
  
          if (conditions for possible move...):
              return(some_function(self.x, self.y, self.u, self.v)) ## applies the move
  
          else:
              return("Move impossible. Try again.")
  </code></pre>
  
  <p>When the move is possible, the function moves the piece on the board and when the move is not possible, it returns a string that says "Move impossible".</p>
  
  <p>I have a lot of testing to do, so to simplify my life I made a seconde function:</p>
  
  <pre><code>def play()
      a = input()
      b = []
      for i in a:
          b.append(i)
      return(move(b[0], b[1], b[2], b[3]))
  </code></pre>
  
  <p>and I put it in an infinite loop so I can keep trying move after move.</p>
  
  <pre><code>while True:
      play()
  </code></pre>
  
  <p>The whole thing is working properly, the pieces are moved according to the rules of the game and everything is fine except that when the move is impossible I don't get the "Move impossible" message.</p>
  
  <p>If I call play() by itself (outside of the while loop, in the shell for example), and attempt an impossible move, I do get the message.</p>
  
  <p>I'm pretty sure this is something very basic but I couldn't find the answer anywhere and I need these messages because I use them to locate errors in the code.</p>
  
  <p>I'll add an example in case it is not clear. Let's say move from (0,0) to (1,1) is impossible.</p>
  
  <p>Case 1, play() without the loop:</p>
  
  <pre><code>&gt;&gt;&gt;play()
  0011
  'Move impossible. Try again.'
  </code></pre>
  
  <p>Case 2, play() inside a loop:</p>
  
  <pre><code>while True:
      play()
  
  0011
  
  0011
  
  ...
  </code></pre>
  
  <p>The move is not played (the piece stays in its place), but I don't get the message. Why is that?</p>
  
  <p>EDIT: Problem solved. </p>
  
  <pre><code>print(play())
  </code></pre>
  
  <p>didn't work, but all I had to do was </p>
  
  <pre><code>return(print("Impossible move"))
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>return("Impossible move")
  </code></pre>
  
  <p>Thank you everyone for the help :) </p>