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


Groups > comp.lang.python > #43832

Re: Novice Issue

From John Gordon <gordon@panix.com>
Newsgroups comp.lang.python
Subject Re: Novice Issue
Date 2013-04-18 14:21 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <kkovhf$ftp$1@reader1.panix.com> (permalink)
References <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com>

Show all headers | View raw


In <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> Bradley Wright <bradley.wright.biz@gmail.com> writes:

> while raw_input != "quit" or "q":

Others have pointed out flaws in this statement.  However, even if you
had written the loop the 'correct' way:

    user_input = raw_input()
    while user_input != "quit" or user_input != "q":

There is still a logic bug.  This loop will execute forever, because no
matter what the user enters, it will be unequal to "q" or unequal to "quit".
Use 'and' instead of 'or'.

Of course in this specific situation, as others have suggested, 'in' is
better still.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

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


Thread

Novice Issue Bradley Wright <bradley.wright.biz@gmail.com> - 2013-04-17 21:06 -0700
  Re: Novice Issue Chris Angelico <rosuav@gmail.com> - 2013-04-18 14:14 +1000
  Re: Novice Issue Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-04-18 08:58 +0000
  Re: Novice Issue Chris Angelico <rosuav@gmail.com> - 2013-04-18 19:06 +1000
  Re: Novice Issue Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-18 11:10 +0100
  Re: Novice Issue Bradley Wright <bradley.wright.biz@gmail.com> - 2013-04-18 05:18 -0700
    Re: Novice Issue Dave Angel <davea@davea.name> - 2013-04-18 08:29 -0400
  Re: Novice Issue Bradley Wright <bradley.wright.biz@gmail.com> - 2013-04-18 05:34 -0700
  Re: Novice Issue John Gordon <gordon@panix.com> - 2013-04-18 14:21 +0000

csiph-web