Re: while loop - multiple condition

2014-10-14 Thread Chris Angelico
On Wed, Oct 15, 2014 at 10:04 AM, giacomo boffi wrote: > Tim Chase writes: > >> On 2014-10-12 22:16, Marko Rauhamaa wrote: >>> is equivalent with >>> >>> while ans.lower()[0] != 'y': >>> ans = input('Do you like python?') >> >> And still better improved with >> >> while ans[:1].low

Re: while loop - multiple condition

2014-10-14 Thread giacomo boffi
Tim Chase writes: > On 2014-10-12 22:16, Marko Rauhamaa wrote: >> is equivalent with >> >> while ans.lower()[0] != 'y': >> ans = input('Do you like python?') > > And still better improved with > > while ans[:1].lower() != 'y': > ans = input('Do you like python?') yok is Turk

Re: while loop - multiple condition

2014-10-13 Thread Michael Torrie
On 10/13/2014 11:12 AM, Rustom Mody wrote: > On Monday, October 13, 2014 10:13:20 PM UTC+5:30, Rob Gaddi wrote: >> On Mon, 13 Oct 2014 09:26:57 -0700 (PDT) >> Rustom Mody wrote: > >>> On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote: On Mon, 13 Oct 2014 09:56:02 +1100 St

Re: while loop - multiple condition

2014-10-13 Thread Rustom Mody
On Monday, October 13, 2014 10:13:20 PM UTC+5:30, Rob Gaddi wrote: > On Mon, 13 Oct 2014 09:26:57 -0700 (PDT) > Rustom Mody wrote: > > On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote: > > > On Mon, 13 Oct 2014 09:56:02 +1100 > > > Steven D'Aprano wrote: > > > > When you have mul

Re: while loop - multiple condition

2014-10-13 Thread Rob Gaddi
On Mon, 13 Oct 2014 09:26:57 -0700 (PDT) Rustom Mody wrote: > On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote: > > On Mon, 13 Oct 2014 09:56:02 +1100 > > Steven D'Aprano wrote: > > > When you have multiple clauses in the condition, it's easier to reason > > > about > > > them i

Re: while loop - multiple condition

2014-10-13 Thread Rustom Mody
On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote: > On Mon, 13 Oct 2014 09:56:02 +1100 > Steven D'Aprano wrote: > > When you have multiple clauses in the condition, it's easier to reason about > > them if you write the clauses as positive statements rather than negative > > stateme

Re: while loop - multiple condition

2014-10-13 Thread Rob Gaddi
On Mon, 13 Oct 2014 09:56:02 +1100 Steven D'Aprano wrote: > > When you have multiple clauses in the condition, it's easier to reason about > them if you write the clauses as positive statements rather than negative > statements, that is, "something is true" rather than "something is not > true",

Re: while loop - multiple condition

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 11:09 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> Or, even simpler: Use an active condition. >> >> while input('Do you like python?') not in ('yes', 'y'): pass > > Instead of the traditional "pull" technology, you could take advantage > of the state-of-the-art "push"

Re: while loop - multiple condition

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 11:10 PM, Skip Montanaro wrote: > On Mon, Oct 13, 2014 at 6:59 AM, Chris Angelico wrote: >> >> while input('Do you like python?') not in ('yes', 'y'): pass > > > Unfortunately, you probably have to account for people who SHOUT: > > while input('Do you like python?').lo

Re: while loop - multiple condition

2014-10-13 Thread Skip Montanaro
On Mon, Oct 13, 2014 at 6:59 AM, Chris Angelico wrote: > while input('Do you like python?') not in ('yes', 'y'): pass Unfortunately, you probably have to account for people who SHOUT: while input('Do you like python?').lower() not in ('yes', 'y'): pass Skip -- https://mail.python.org/m

Re: while loop - multiple condition

2014-10-13 Thread Marko Rauhamaa
Chris Angelico : > Or, even simpler: Use an active condition. > > while input('Do you like python?') not in ('yes', 'y'): pass Instead of the traditional "pull" technology, you could take advantage of the state-of-the-art "push" approach: print("You must love python -- everybody does!") Mar

Re: while loop - multiple condition

2014-10-13 Thread Chris Angelico
On Mon, Oct 13, 2014 at 7:31 PM, Gelonida N wrote: > 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 Or, even simpler: Use an active conditio

Re: while loop - multiple condition

2014-10-13 Thread Gelonida N
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 ha

Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 11:43 AM, Dennis Lee Bieber wrote: > 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). Short-circuiting doesn't

Re: while loop - multiple condition

2014-10-12 Thread Steven D'Aprano
Tim Chase wrote: > On 2014-10-12 22:16, Marko Rauhamaa wrote: >> is equivalent with >> >> while ans.lower()[0] != 'y': >> ans = input('Do you like python?') > > And still better improved with > > while ans[:1].lower() != 'y': > ans = input('Do you like python?') The intenti

Re: while loop - multiple condition

2014-10-12 Thread Tim Chase
On 2014-10-12 22:16, Marko Rauhamaa wrote: > is equivalent with > > while ans.lower()[0] != 'y': > ans = input('Do you like python?') And still better improved with while ans[:1].lower() != 'y': ans = input('Do you like python?') in the event that len(ans)==0 (a situation whi

Re: while loop - multiple condition

2014-10-12 Thread Denis McMahon
On Sun, 12 Oct 2014 17:08:00 +, Shiva wrote: > while ans.lower() != 'yes' or ans.lower()[0] != 'y': while ans.lower() is not equal to "yes" or ans.lower()[0] is not equal to "y" the loop will continue to run Note that if ans.lower() == 'y', then the first clause ( ans.lower() != 'yes' )

Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 6:16 AM, Marko Rauhamaa wrote: > The corrected version > > while ans.lower() != 'yes' and ans.lower()[0] != 'y': > ans = input('Do you like python?') > > is equivalent with > > while ans.lower()[0] != 'y': It's true that the first part is redundant, but tr

Re: while loop - multiple condition

2014-10-12 Thread Marko Rauhamaa
Chris Angelico : > On Mon, Oct 13, 2014 at 4:59 AM, Shiva > wrote: >> Bit confusing to use in While loop - Should have used the 'and' condition >> instead of OR- then it works fine. >> for OR both condition need to be false to produce a false output and break >> the loop. > > Correct, what you're

Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 4:59 AM, Shiva wrote: > Bit confusing to use in While loop - Should have used the 'and' condition > instead of OR- then it works fine. > for OR both condition need to be false to produce a false output and break > the loop. Correct, what you're looking for here is indeed a

Re: while loop - multiple condition

2014-10-12 Thread Shiva
Bit confusing to use in While loop - Should have used the 'and' condition instead of OR- then it works fine. for OR both condition need to be false to produce a false output and break the loop. More of SET operations. Thanks, Shiva -- https://mail.python.org/mailman/listinfo/python-list

Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 4:21 AM, Shiva wrote: >> The loop will continue while either part is true - that's what "or" >> means. Is that what you intended it to be doing? >> >> ChrisA >> > > > Yes..however, the second part of the or condition doesn't get evaluated. > So if I enter a 'y' - I expe

Re: while loop - multiple condition

2014-10-12 Thread Roy Smith
In article , Shiva wrote: > 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 aft

Re: while loop - multiple condition

2014-10-12 Thread Shiva
> The loop will continue while either part is true - that's what "or" > means. Is that what you intended it to be doing? > > ChrisA > Yes..however, the second part of the or condition doesn't get evaluated. So if I enter a 'y' - I expect the second part to evaluate and the loop to break -

Re: while loop - multiple condition

2014-10-12 Thread Chris Angelico
On Mon, Oct 13, 2014 at 4:08 AM, Shiva wrote: > 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 th