python give option if user inputs string
<p>I'm using Python 2.6.6</p>

<p>I have this code:</p>

<pre><code>height = 20
width = 10
x = input('Please insert a number between ' + str(width + 1) + ' and ' + str(height) + ': ')
while x &lt; (width + 1) or x &gt; 20:
     print 'That option is not valid'
     x = input('Please insert a number between ' + str(width + 1) + ' and ' + str(height) + ': ')
</code></pre>

<p>If the user only inputs number, everything works OK but if the user makes a mistake and type, for example q, it gives : </p>

<blockquote>
  <p>NameError: name 'q' is not defined</p>
</blockquote>

<p>I want, if the user inserts a string, the while loop kicks in and give the user: That option is not valid....
How can I solve this without using raw_input since width and height I want to treat tham as numbers?</p>

<p>Regards,</p>

<p>Favolas</p>

<p><strong>EDIT</strong> 
Following Daniel suggestion, I've modified my code to this:</p>

<pre><code>height = 20
width = 10
x = raw_input('Please insert a number between ' + str(width + 1) + ' and ' + str(height) + ': ')
x = int(x)
while x &lt; (width + 1) or x &gt; 20:
    print 'That option is not valid'
    x = raw_input('Please insert a number between ' + str(width + 1) + ' and ' + str(height) + ': ')
    x = int(x)
</code></pre>

<p>If the user only inputs int code works as planned but its not safe from user errors. If the users, makes a mistake and types 'q' it gives this error:</p>

<pre><code>ValueError: invalid literal for int() with base 10: 'q'
</code></pre>

<p>I understand why but how do I solve this?</p>

<p>Regards,</p>

<p>Favolas</p>
