python nested if statements not working
<p>I'm trying to make a game using pygame, and I've set up a couple of functions that I've tested and they work fine. However, in the code below, when I add a print statement to show if my code works, it prints on the first one but not the second.  Any help?</p>

<pre><code>for square in row:
    tile_x = row.index(square)
    # print statement works here
    if self.x_pos - tile_x &gt;= -4 and self.x_pos - tile_x &lt;= 4:
        tile_x = 4 - (self.x_pos - tile_x)
        tile_y = 4 - (self.y_pos - tile_y)
        if square == 'G':
            display('Grass',tile_x,tile_y)
            # print statement doesn't work here
        elif square == 'T':
            display('Tree',tile_x,tile_y)
        elif square == 'B':
            display('Bush',tile_x,tile_y)
        elif square == 'R':
            display('Rock',tile_x,tile_y)
        elif square == 'S':
            display('Stone',tile_x,tile_y)
        # display function has been tested, and it works fine
</code></pre>

<p>I have just thought of something</p>

<p>I am using <code>row.index(square)</code>, which is finding the <strong>first</strong> 'g' square and using the tile_x of <strong>that</strong> first square. This means it thinks the square I'm looking for is not in the correct range to show on the map, so the first if statement returns False and it doesn't show up or print out.</p>

python if-statement