[Tutor] Paper Rock Scissors game - User's choice not returned properly

Joel Montes de Oca joelmontes01 at gmail.com
Tue Nov 1 03:45:37 CET 2011


On 10/31/2011 07:10 PM, Steven D'Aprano wrote:
> Alan Gauld wrote:
>> On 31/10/11 20:22, Peter Otten wrote:
>>> Alan Gauld wrote:
>>>
>>>> if choice.lower() not in ('prs'): # NB use a single string
>>>
>>> That's not a good idea. If a user accidentally enters PR (for 
>>> example) your
>>> version will mistake that for a valid choice.
>>
>> Good point, although  you could test the first character only...
>>
>> if choice[0].lower() not in ('prs'): # NB use a single string
>
> Why would you do that? If the user is supposed to enter a single 
> letter, why would you accept (for example) "screw you hippy, I hate 
> this game!" as the valid response "s"?
>
>
>
I agree, I am not sure that I see the benefit of using a single string. 
If anything, it makes it a bit harder to read by someone other than the 
person who wrote it.

    if choice.lower() in ('p', 'r','s'):

I think the code above is a lot clearer.

-- 
-Joel M.



More information about the Tutor mailing list