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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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