Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79039 > unrolled thread

Re: while loop - multiple condition

Started byGelonida N <gelonida@gmail.com>
First post2014-10-13 10:31 +0200
Last post2014-10-13 10:31 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: while loop - multiple condition Gelonida N <gelonida@gmail.com> - 2014-10-13 10:31 +0200

#79039 — Re: while loop - multiple condition

FromGelonida N <gelonida@gmail.com>
Date2014-10-13 10:31 +0200
SubjectRe: while loop - multiple condition
Message-ID<mailman.14815.1413189132.18130.python-list@python.org>
On 10/12/2014 07:08 PM, Shiva wrote:
> while ans.lower() != 'yes' or ans.lower()[0] != 'y':
>       ans = input('Do you like python?')

I personally consider double negations less intuitive than following:


while not( ans.lower() == 'yes' and ans.lower()[0] == 'y' ):

Reading this line yoy would have noticed as wellm that what you really 
wanted would have been:

while not( ans.lower() == 'yes' or ans.lower()[0] == 'y' ):



I would write the coder differently.

With your code you have to pre-initialze the variable ans.


I personally consider it also more 'intuitive' / easier to understand if
I can see the break conditiion. to many nots  / != / negations can be 
confusing as you noticed yourself.

Taking into account the Steven's suggestion about using the 'in' 
expression it could be:


while True:
     ans = input('Do you like python?')
     if ans.lower() in ('yes', 'y'):
         break





[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web