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

D-Man dman@westsidecnc.rh.rit.edu
Wed, 6 Dec 2000 11:05:08 -0500 (EST)


> 
> > while ( string.upper( x ) not in ( 'N' , 'L' ) ) :
> > # body of loop here
> 
> I'm a beginner at all this, but I do think the above statement is much
> clearer. However, I don't think anyone has shown how the original statement
> should have looked. I know it helps me when I know why something doesn't
> work, and I think I also misunderstood the same thing at one time.
> 
> 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':

I use the 'toupper' function (in C) because of long expressions like the above.  Python provides a simpler way using a list.

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

That is equivalent to your correct expression.

> 
> 
> Brad
> 

-D