Python Script Loop
<p>I wrote the following python script to implement my version of the game nims/stones</p>

<pre><code>def nims_stones(pile, max_stones):

    while pile !=  0:

        move = 0

        while move &lt; 1 or move &gt; max_stones:
            move = int(raw_input("Player 1 How Many Stones"))
        pile -= move

        if pile == 0:
            print "Player 1 wins"

        else:
            print "There are %s stones left." %(pile)



        move = 0

        while move &lt; 1 or move &gt; max_stones:
            move = int(raw_input("Player 2 How Many Stones"))
        pile -= move

        if pile == 0:
            print "Player 2 wins"

        else:
            print "There are %s stones left." %(pile)

    print "Game Over"
</code></pre>

<p>When I call the function nims_stones(10,5) It seems to work but after player one or player two wins it doesn't exit the loop it doesn't print "Game Over" it just asks for the next move</p>

<p>I don't know why it doesn't exit the loop after a player wins. Any help will be greatly appreciated.</p>

<p>You should stop the loop when player 1 has emptied the pile. As you have almost the same code for the second player, consider reusing the code. Then you'll also have the empty pile check at the end of the loop:</p>

<pre><code>def nims_stones(pile, max_stones):
    player = 2
    while pile !=  0:
        player = 3 - player
        move = 0
        while move &lt; 1 or move &gt; max_stones or move &gt; pile:
            move = int(raw_input("Player %i. How Many Stones" % (player)))
        pile -= move
        print ("There are %s stones left." %(pile))
    print ("Player %i wins" % (player))
    print ("Game Over")
</code></pre>

<p>NB/ I also added the condition <code>move &gt; pile</code> to avoid players taking more than available.</p>

python