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


Groups > comp.lang.python > #79039

Re: while loop - multiple condition

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.020
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'differently.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:while': 0.09; 'ans': 0.16; 'be:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'true:': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'header:User- Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'code': 0.31; 'easier': 0.31; 'yourself.': 0.31; 'received:fr': 0.33; 'noticed': 0.34; 'could': 0.34; 'really': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'expression': 0.60; 'break': 0.61; 'more': 0.64; 'taking': 0.65; 'account': 0.65; 'charset:windows-1252': 0.65; 'received:109': 0.72; 'confusing': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Gelonida N <gelonida@gmail.com>
Subject Re: while loop - multiple condition
Date Mon, 13 Oct 2014 10:31:56 +0200
References <loom.20141012T190458-947@post.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 1-75-190-109.dsl.ovh.fr
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2
In-Reply-To <loom.20141012T190458-947@post.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14815.1413189132.18130.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1413189132 news.xs4all.nl 2952 [2001:888:2000:d::a6]:58405
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 3504
X-Received-Body-CRC 3566021196
Xref csiph.com comp.lang.python:79039

Show key headers only | View raw


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





Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web