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


Groups > comp.lang.python > #52234

Re: Issues with if and elif statements in 3.3

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Issues with if and elif statements in 3.3
Date 2013-08-08 19:31 -0400
Organization IISS Elusive Unicorn
References <02128546-7a5d-4fe8-a472-47cfd4f76342@googlegroups.com> <ktvs8f$ei2$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.378.1376004726.1251.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, 8 Aug 2013 10:34:57 +0000 (UTC), Dave Angel <davea@davea.name>
declaimed the following:

>
>Or less typing:
>
>if answer in ("yes", "Yes", "y"):
>

	Or (IF there is no chance for ambiguity)

	if answer.lower().startswith("y"):

	If there is ambiguity, provide enough of the matchword to determine the
unique option...

	if answer.lower().startswith("ye"):
		do_Yell_Action(rest_of_input_line)
	elif answer.lower().startswith("yi"):
		do_Yield_Action(rest_of_input_line)

	Granted, if parsing command options, you might want to lift the
.lower() out of the "if" conditions

	answer = answer.lower()
	if answer.startswith(...

{to expand (2.x syntax)}

	command = raw_input("Enter command> ")
	command = command.lower().split()

	(answer, args) = (command[0], command[1:])

	operation = None
	if answer.startswith("ye"):
		operation = do_Yell_Action
	elif answer.startswith("yi"):
		operation = do_Yield_Action
	elif answer.startswith("dr"):
		operation = do_Drop_Action
...

	if operation is not None:
		operation(args)
	else:
		print "That is not a valid command"


>
>
>
>>         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.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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