How to accept only 5 possible inputs
<p>In my program I have a menu that looks like this:</p>

<pre><code>MenuChoice = ''
while MenuChoice != 'x':
print("Type 1 to enter the first option")
print("Type 2 to enter the second option")
print("Type 3 to enter the third option")
print("Type 4 to enter the fourth option")
print("Press x to quit")
try: 
    MenuChoice = str(input("Please enter your choice here -----------------&gt;&gt;&gt;&gt;&gt;")) 
except ValueError: 
    print("Please enter one of the menu choices above, TRY AGAIN ") 
</code></pre>

<p>I just want to know a way in which I can insure that only the numbers 1 to 5 are accepted and that if anything else is entered then the program asks the question again.</p>

<p>Please dont roast me.</p>

<p>Thanks</p>

<p>I think he needs a While true loop . Did using python 2.X</p>

<pre><code>import time
print("Type 1 to enter the first option")
print("Type 2 to enter the second option")
print("Type 3 to enter the third option")
print("Type 4 to enter the fourth option")
print("Press x to quit")

while True:
    try:
        print ("Only Use number 1 to 4 or x to Quit... Thanks please try again")
        MenuChoice = raw_input("Please enter your choice here -----------------&gt;&gt;&gt;&gt;&gt; ")
        try:
            MenuChoice = int(MenuChoice)
        except:
            MenuChoice1 = str(MenuChoice)
        if MenuChoice1 == 'x' or 1 &lt;= MenuChoice &lt;= 4:
            print "You selected %r Option.. Thank you &amp; good bye"%(MenuChoice)
            time.sleep(2)
            break
    except:
        pass
</code></pre>

python error-handling menu