While loop with "or"? Please help!

Tim Williams tim at tdw.net
Thu Jan 25 07:53:01 EST 2007


On 25/01/07, Bruno Desthuilliers <bruno.desthuilliers at websiteburo.com> wrote:
> Peter Otten a écrit :
> > Bruno Desthuilliers wrote:
> >
> >> and simplified again thanks to Python 'in' operator:
> >> while not usrinp.lower() in "yn":
> >
> > But note that 'in' performs a substring search and therefore "yn" and ""
> > would be accepted as valid answers, too.
>
> Mmm, right. Thanks for the correction.
>
> =>
>    while not usrinp.lower() in ['y', 'n']:

or better still

while usrinp.lower() not in ['y', 'n']:

:):)


-- 

Tim Williams



More information about the Python-list mailing list