Hi,<div><br></div><div>I&#39;m writing a text based menu and want to validate the user input. I&#39;m giving the options as integers, and I want to make sure the user enters a proper value.</div><div><br></div><div>Here&#39;s what I&#39;ve got so far: <a href="http://pastebin.com/m1fdd5863">http://pastebin.com/m1fdd5863</a></div>

<div><br></div><div>I&#39;m most interested in this segment:</div><div><br></div><div><div>    while True:</div><div><div><div>        choice = raw_input(prompt)</div><div>        if valid_choice(choice, 0, len(options)-1):</div>

<div>            break</div><div><br></div><div>    return choice</div></div></div><div><br></div><div>Is that the most pythonic way of validating? Is there a better way?</div><div><br></div></div><div>As an aside, in the valid_choice function I know I could do:</div>

<div><br></div><div>if not choice in range(min, max)</div><div><br></div><div>but I figured a comparison would probably be the better choice, correct?</div><div><br></div><div>Thanks,</div><div>Wayne<br>-- <br>To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn’t. - Primo Levi<br>


</div>