Problem I have with a while loop/boolean/or

Scott David Daniels scott.daniels at acm.org
Wed Mar 14 01:19:08 EDT 2007


Bart Willems wrote:
> ...
> I always try to stay away from 'negative' operators if possible, to 
> improve readability:
> 
> while True:
>    hint = raw_input('\nAre you stuck? y/n: ').lower()
>    if hint = 'y' or hint = 'n':
>       break
>    else:
>       print 'Please answer yes or no'

And if you really want to see what is going wrong, replace that last by:
         print 'Please answer yes or no (not %r):' % hint

-- 
--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list