Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79027 > unrolled thread
| Started by | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| First post | 2014-10-12 20:43 -0400 |
| Last post | 2014-10-12 20:43 -0400 |
| 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.
Re: while loop - multiple condition Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-12 20:43 -0400
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2014-10-12 20:43 -0400 |
| Subject | Re: while loop - multiple condition |
| Message-ID | <mailman.14806.1413161032.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web