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


Groups > comp.lang.python > #79017

Re: while loop - multiple condition

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: while loop - multiple condition
Date 2014-10-12 22:16 +0300
Organization A noiseless patient Spider
Message-ID <878uklcd3r.fsf@elektro.pacujo.net> (permalink)
References (1 earlier) <CAPTjJmrPgTdysCnLcbMqYFiGGwg-wV_mjfw16Kt15_zuv_624g@mail.gmail.com> <loom.20141012T191849-946@post.gmane.org> <CAPTjJmouQsm_9ccqdtmJ3kmd4SqmmOqk3OVdS4mngeHaVT2S6w@mail.gmail.com> <loom.20141012T195709-937@post.gmane.org> <mailman.14798.1413137019.18130.python-list@python.org>

Show all headers | View raw


Chris Angelico <rosuav@gmail.com>:

> On Mon, Oct 13, 2014 at 4:59 AM, Shiva
> <shivaji_tn@yahoo.com.dmarc.invalid> 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 an 'and' (also called
> a conjunction, as opposed to the disjunction of 'or'). Both operators
> are important; and you need to understand what they do so you know
> when to use each.

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':
         ans = input('Do you like python?')


Marko

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


Thread

Re: while loop - multiple condition Chris Angelico <rosuav@gmail.com> - 2014-10-13 05:03 +1100
  Re: while loop - multiple condition Marko Rauhamaa <marko@pacujo.net> - 2014-10-12 22:16 +0300
    Re: while loop - multiple condition Chris Angelico <rosuav@gmail.com> - 2014-10-13 06:22 +1100
    Re: while loop - multiple condition Tim Chase <python.list@tim.thechases.com> - 2014-10-12 15:42 -0500
      Re: while loop - multiple condition Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-13 09:56 +1100
        Re: while loop - multiple condition Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-13 09:12 -0700
          Re: while loop - multiple condition Rustom Mody <rustompmody@gmail.com> - 2014-10-13 09:26 -0700
            Re: while loop - multiple condition Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-13 09:43 -0700
              Re: while loop - multiple condition Rustom Mody <rustompmody@gmail.com> - 2014-10-13 10:12 -0700
                Re: while loop - multiple condition Michael Torrie <torriem@gmail.com> - 2014-10-13 16:08 -0600
                Re: while loop - multiple condition wxjmfauth@gmail.com - 2014-10-13 23:34 -0700
      Re: while loop - multiple condition giacomo boffi <pecore@pascolo.net> - 2014-10-15 01:04 +0200
        Re: while loop - multiple condition Chris Angelico <rosuav@gmail.com> - 2014-10-15 10:16 +1100

csiph-web