On 08/12/14 02:24, Steven D'Aprano wrote:

Python sees it like:

if FirstChoice == ('Coke' or 'Pepsi' or 'Water'):

So evaluates the bit in parens first which results in a boolean value of
True.


Actually it sees it as:

if ((FirstChoice == 'Coke') or 'Pepsi' or 'Water'):

which will always evaluate as True.

Oops, you're right.
Always test...

# The short way
if FirstChoice in ('Coke', 'Pepsi', 'Water'):

Which is what I was suggesting so we get to the same end game :-)


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to