Problem I have with a while loop/boolean/or

Steve Holden steve at holdenweb.com
Wed Mar 14 08:19:00 EDT 2007


Scott David Daniels wrote:
> 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
> 
Better still, use

   Please answer y or n

since those are the values you are testing for ...

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Blog of Note:          http://holdenweb.blogspot.com
See you at PyCon?         http://us.pycon.org/TX2007




More information about the Python-list mailing list