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


Groups > comp.lang.python > #79027

Re: while loop - multiple condition

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!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.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'clause': 0.09; 'converts': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'seen,': 0.09; 'subject:while': 0.09; 'python': 0.11; 'ans': 0.16; 'message- id:@4ax.com': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'looked': 0.18; '+0000': 0.22; 'url:home': 0.24; "haven't": 0.24; 'second': 0.26; '(for': 0.26; 'header:X-Complaints-To:1': 0.27; 'character': 0.29; "doesn't": 0.30; 'equal': 0.35; 'but': 0.35; 'false': 0.36; 'charset:us- ascii': 0.36; 'should': 0.36; 'being': 0.38; 'to:addr:python- list': 0.38; 'short': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'above,': 0.60; 'first': 0.61; 'college': 0.70; 'applying': 0.72; 'break.': 0.84; 'circuit': 0.84; 'forgotten': 0.91; 'received:108': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: while loop - multiple condition
Date Sun, 12 Oct 2014 20:43:39 -0400
Organization IISS Elusive Unicorn
References <loom.20141012T190458-947@post.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host adsl-108-73-116-39.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 6.00/32.1186
X-No-Archive YES
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.14806.1413161032.18130.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1413161032 news.xs4all.nl 2870 [2001:888:2000:d::a6]:56700
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:79027

Show key headers only | View raw


On Sun, 12 Oct 2014 17:08:00 +0000 (UTC), Shiva
<shivaji_tn@yahoo.com.dmarc.invalid> declaimed the following:

>Why is the second part of while condition not being checked?
>
>while ans.lower() != 'yes' or ans.lower()[0] != 'y':
>     ans = input('Do you like python?')
>
>
>My intention is if either of the conditions are true the loop should break.
>But the condition after 'or' doesn't seem to evaluate.
>
	ONE: Python uses short circuit evaluation: for an OR, the second clause
is only looked at if the first clause is FALSE (for an AND, the first
clause has to be TRUE before the second is evaluated).

	The only way for the second clause to be seen, above, is for the first
clause to be false -- that means ans IS EQUAL to "yes", but that condition
also means the first character is equal to "y".

	Applying de Morgan's (if I haven't forgotten my 37 year old college
courses)

	A not equal B OR C not equal D
converts into
	NOT (A equal B AND C equal D)

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


Thread

Re: while loop - multiple condition Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-12 20:43 -0400

csiph-web