<div class="gmail_quote">On Mon, Oct 31, 2011 at 1:14 PM, Marc Tompkins <span dir="ltr">&lt;<a href="mailto:marc.tompkins@gmail.com">marc.tompkins@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im"><br>
</div>You could simplify it even further by actually using the &quot;while&quot;:<br>
<div class="im"><br>
&gt; def UserChoice ():    # The function that returns the choice from the user<br>
</div>&gt;    choice = &#39;&#39;<br>
&gt;    attempt = 0<br>
&gt;    while choice.lower() not in (&#39;p&#39;, &#39;r&#39;,&#39;s&#39;):<br>
&gt;        if attempt &gt; 0: print &#39;Please try again.&#39;<br>
<div class="im">&gt;        print &#39;Please select (P) for paper, (R) for Rock, or (S) for Scissors.&#39;<br>
&gt;        choice = raw_input(&#39;What is your selection?: &#39;)<br>
</div>&gt;        attempt +=1<br>
&gt;    return choice.lower()<br>
<br>
It&#39;s a matter of personal preference, but I try to avoid &quot;while 1&quot; or<br>
&quot;while True&quot; loops if at all possible.  For one thing, it seems<br>
counter-productive to set up a loop that doesn&#39;t exit, and then to<br>
have to use &#39;break&#39; to get out of it!<br></blockquote><div><br></div><div>As a slight aside, I came up with a (fairly) simple recipe for this sort of occasion:</div><div><br></div><div>def prompt(choices):</div><div>

    try:</div><div>        for choice, desc in choices:</div><div>            print(&quot;%2s. %s&quot; % (choice, desc))</div><div>        prompt.choice = input(&quot;Choice: &quot;) #use raw_input in Python 2.x</div><div>

        print()</div><div>        return prompt.choice</div><div>    except TypeError:</div><div>        raise ValueError(&quot;prompt expects collection of pairs&quot;)</div><div><br></div><div>Then you can do something like this:</div>

<div><br></div><div>while prompt([(&quot;P&quot;, &quot;Paper&quot;), (&quot;R&quot;, &quot;Rock&quot;), (&quot;S&quot;, &quot;Scissors)]).lower() not in (&#39;p&#39;, &#39;r&#39;, &#39;s&#39;):</div><div>    print(&quot;Error: &quot;, prompt.choice, &quot; is not a valid choice!&quot;)</div>

<div><br></div><div>#do something with prompt.choice here</div><div><br></div><div>It handles keeping track of whatever the last choice was for you, and all you have to do is pass it a collection of pairs. If you wanted to make it specifically for your application, you could just change it to this:</div>

<div><br></div><div>def prompt():</div><div>   print(&quot;(P)aper&quot;)</div><div>   print(&quot;(R)ock&quot;)</div><div>   print(&quot;or (S)cissors?&quot;)<br>   prompt.choice = raw_input(&quot;Choice: &quot;)</div><div>

   return prompt.choice</div><div><br></div><div>while prompt().lower() not in (&#39;p&#39;, &#39;r&#39;, &#39;s&#39;):</div><div>   #print error message</div><div><br></div><div>HTH,</div><div>Wayne</div></div>