[Tutor] while x != 'n' or 'N' or 'l' or 'L':

Simon Brunning SBrunning@trisystems.co.uk
Wed, 6 Dec 2000 15:29:01 -0000


> From:	Brad Chandler [SMTP:mbc2@netdoor.com]
> The original statement:
> while x != 'n' or 'N' or 'l' or 'L':
> 
> Should have been:
> while x != 'n' or x != 'N' or x != 'l' or x != 'L':
 
No! 

while x != 'n' or x != 'N' or x != 'l' or x != 'L':

is *exactly* equivalent to:

while 1:

- it will *always* be true, and will loop forever. I suspect that you mean:

while x != 'n' and x != 'N' and x != 'l' and x != 'L':

But as has been pointed out, the pythonic way of doing this is:

while x not in ('n', 'N', 'l', 'L'):

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning@trisystems.co.uk





-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.