Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52068
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'elif': 0.05; 'false.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:question': 0.10; 'def': 0.12; '"yes":': 0.16; 'email addr:comcast.net': 0.16; 'evaluates': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'think.': 0.16; 'wrote:': 0.18; 'meant': 0.20; 'thanks.': 0.20; 'header:User-Agent:1': 0.23; 'logical': 0.24; 'header:X -Complaints-To:1': 0.27; "doesn't": 0.30; 'code': 0.31; 'comparison': 0.31; 'prints': 0.31; 'could': 0.34; 'right?': 0.36; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'expression': 0.60; 'matter': 0.61; 'first': 0.61; 'more': 0.64; 'results': 0.69; 'succeed.': 0.84; 'was:': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dave Angel <davea@davea.name> |
| Subject | Re: Beginner question |
| Date | Tue, 6 Aug 2013 22:03:57 +0000 (UTC) |
| References | <6e80b2f8-0b14-43cd-b8af-211ef65d73ba@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=US-ASCII |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | 174.32.174.31 |
| User-Agent | XPN/1.2.6 (Street Spirit ; Linux) |
| 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.273.1375826661.1251.python-list@python.org> (permalink) |
| Lines | 34 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1375826661 news.xs4all.nl 15888 [2001:888:2000:d::a6]:35725 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:52068 |
Show key headers only | View raw
eschneider92@comcast.net wrote:
> Why won't the 'goodbye' part of this code work right? it prints 'ok' no matter what is typed. Much thanks.
>
> def thing():
> print('go again?')
> goagain=input()
> if goagain=='y' or 'yes':
This expression doesn't do what you think. The comparison binds more
tightly, so it first evaluates (goagain=="y"). The results of that are
either True or False. Then it or's that logical value with 'yes'. The
result is either True or it's 'yes'. 'yes' is considered truthy, so
the if will always succeed.
What you meant to use was:
if goagain == "y" or goagain == "yes":
Alternatively, you could use
if goagain in ("y", "yes"):
> print('ok')
> elif goagain!='y' or 'yes':
Same here.
> print('goodbye')
> sys.exit()
> thing()
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Beginner question eschneider92@comcast.net - 2013-08-06 14:35 -0700 Re: Beginner question Dave Angel <davea@davea.name> - 2013-08-06 22:03 +0000 Re: Beginner question Chris Angelico <rosuav@gmail.com> - 2013-08-06 23:10 +0100 Re: Beginner question "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2013-08-06 23:14 +0100 Re: Beginner question Chris Down <chris@chrisdown.name> - 2013-08-06 23:46 +0200 Re: Beginner question eschneider92@comcast.net - 2013-08-06 20:06 -0700
csiph-web