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


Groups > comp.lang.python > #43811

Re: Novice Issue

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'true,': 0.05; '(python': 0.07; 'test,': 0.07; 'string': 0.09; 'preferable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'things,': 0.09; 'typed': 0.09; 'way:': 0.09; 'python': 0.11; '"or"': 0.16; "chris'": 0.16; 'message-id:@post.gmane.org': 0.16; 'pythonic': 0.16; 'received:80.91.229.3': 0.16; 'received:mediaways.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:pool.mediaways.net': 0.16; 'stops.': 0.16; 'all,': 0.19; 'subject:Issue': 0.19; 'tests': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'sort': 0.25; "i've": 0.25; 'script': 0.25; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; 'testing': 0.29; 'getting': 0.31; 'conditions:': 0.31; 'minor': 0.31; 'wright': 0.31; 'writes:': 0.31; 'anyone': 0.31; "can't": 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'doing': 0.36; 'charset:us- ascii': 0.36; 'two': 0.37; 'conditions.': 0.38; 'to:addr:python- list': 0.38; 'issue': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'users': 0.40; 'how': 0.40; 'numbers': 0.61; "you're": 0.61; 'first': 0.61; 'information': 0.63; 'name': 0.63; 'more': 0.64; 'here': 0.66; 'gotten': 0.74; 'day': 0.76
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Subject Re: Novice Issue
Date Thu, 18 Apr 2013 08:58:56 +0000 (UTC)
References <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host sea.gmane.org
User-Agent Loom/3.14 (http://gmane.org/)
X-Loom-IP 77.2.134.58 (Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0)
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.757.1366275551.3114.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366275551 news.xs4all.nl 2250 [2001:888:2000:d::a6]:47682
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43811

Show key headers only | View raw


Bradley Wright <bradley.wright.biz <at> gmail.com> writes:

> 
> Good Day all, currently writing a script that ask the user for three things;
> 1.Name
> 2.Number
> 3.Description
> I've gotten it to do this hurah!
> 
> print "Type \"q\" or \"quit\" to quit"
> while raw_input != "quit" or "q":
> 
>     print ""
>     name = str(raw_input("Name: "))
>     number = str(raw_input("Number: "))
>     description = str(raw_input("Description: "))
> 
> but here a few things, can anyone help me on figuring out how to at the
users whim print out all of the names,
> numbers and descriptions. this is sort of an information logger.
> 
> additionally, minor issue with getting script to stop when q or quit is typed

your minor issue here is your "or" test, which is not doing what you think
it does.
You're testing here for either of the following to conditions:
1) raw_input != "quit"
2) "q" (Python can't know that you want raw_input != "q" here!!)
Now any non-empty string in Python tests True, so your while loop never stops.
There are two solutions for that:
the obvious: while not (raw_input == "quit" or raw_input == "q")
or the pythonic way: while raw_input not in ("quit", "q")
The second form definitely is preferable over the first when you have to
test for more than two conditions.
For your other questions see Chris' answers.

Best,
Wolfgang


Back to comp.lang.python | Previous | NextPrevious in thread | Next 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