Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52185
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re: Issues with if and elif statements in 3.3 |
| Date | 2013-08-08 10:34 +0000 |
| References | <02128546-7a5d-4fe8-a472-47cfd4f76342@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.346.1375958120.1251.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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