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


Groups > comp.lang.python > #52185

Re: Issues with if and elif statements in 3.3

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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; 'else:': 0.03; 'elif': 0.05; 'true,': 0.05; '"if': 0.09; '"no"': 0.09; 'executes': 0.09; 'next,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; '"elif"': 0.16; 'bool': 0.16; 'compares': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:3.3': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'input': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; '"you': 0.24; 'regardless': 0.24; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; 'supposed': 0.32; 'subject:with': 0.35; 'something': 0.35; 'charset:us-ascii': 0.36; 'should': 0.36; 'ends': 0.38; 'to:addr :python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'expression': 0.60; 'middle': 0.60; 'first': 0.61; 'email addr:gmail.com': 0.63; 'happen': 0.63; 'stand': 0.64; 'finally': 0.65; 'body.': 0.68; '"under': 0.84; 'presumably': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: Issues with if and elif statements in 3.3
Date Thu, 8 Aug 2013 10:34:57 +0000 (UTC)
References <02128546-7a5d-4fe8-a472-47cfd4f76342@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.346.1375958120.1251.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375958120 news.xs4all.nl 15940 [2001:888:2000:d::a6]:60137
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52185

Show key headers only | View raw


krismesenbrink@gmail.com wrote:

> def town():
>     print ("You stand in the middle of Coffeington while you descide what"
>     " to do next, you have herd rumor of the Coffeington Caves that run"
>     "under the city, would you like to check them out?")
>     answer = input()
>     if answer == ("yes") or ("Yes") or ("y"):

This doesn't do what you think it does.  First it compares answer to
"yes".  Then it takes the result of that and OR's it with "Yes".  Then
it takes the result of that and OR's it with "y".  Finally it takes the
bool of the result and decides whether to execute the if-body.  Since
those OR's will always be true, it always executes the if-body, and
never the elif or else body.

Fix the expression to what you presumably meant:

if answer == "yes" or answer == "Yes" or answer == "y":

Or less typing:

if answer in ("yes", "Yes", "y"):




>         print("You set out for the Coffeington Caves")
>     elif answer == ("no") or ("No") or ("n"):
>         print("Oh...well im sure you can find something else to do")
>     else:
>         print("You just stand  there")
> town()
>
>
>
> i don't know why the "elif" or "else" part of the "if statment" wont trigger. what ends up happening is that regardless of what answer you put in input it will always print out "you set out for the Coffeington Caves". whats supposed to happen is if you say "no" it should just end? i think anway.

-- 
DaveA

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


Thread

Issues with if and elif statements in 3.3 krismesenbrink@gmail.com - 2013-08-08 00:19 -0700
  Re: Issues with if and elif statements in 3.3 Dave Angel <davea@davea.name> - 2013-08-08 10:34 +0000
    Re: Issues with if and elif statements in 3.3 Kris Mesenbrink <krismesenbrink@gmail.com> - 2013-08-08 15:20 -0700
      Re: Issues with if and elif statements in 3.3 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-08 19:37 -0400
  Re: Issues with if and elif statements in 3.3 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-08 19:31 -0400

csiph-web