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


Groups > comp.lang.python > #51283

Re: Help

From Peter Otten <__peter__@web.de>
Subject Re: Help
Date 2013-07-26 07:27 +0200
Organization None
References <067018ce-ca0c-415b-a5d3-3c2f79f11e8e@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.5132.1374816489.3114.python-list@python.org> (permalink)

Show all headers | View raw


tyler@familyrobbins.com wrote:

> I'm a bit new to python and I'm trying to create a simple program which
> adds words and definitions to a list, and then calls them forward when
> asked to.

> while escape < 1:
> 
>     choice = input("Type 'Entry' to add a word to the Dictionary, 'Search'
>     to find a word, and 'Exit' to quit. ")
> 
>     if choice == '`':
>         break
>     
>     if choice == 'Entry' or 'entry':

> However, if I run the program using anything but 'entry', the program
> still runs the 'entry' subroutine. After the 'entry' subroutine is run
> once, no options work. Ex:

The expression 

choice == 'Entry' or 'entry'

is evaluated by Python as

(choice == 'Entry') or 'entry'

All strings but "" are True in a boolean context, so this has the same 
effect as

(choice == 'Entry') or True

and is always True. Possible fixes:

if choice == "Entry" or choice == "entry":
if choice in ("Entry", "entry"):
if choice.casefold() == "entry".casefold(): # will accept ENTRY, eNtRy etc.

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


Thread

Help tyler@familyrobbins.com - 2013-07-25 22:06 -0700
  Re: Help alex23 <wuwei23@gmail.com> - 2013-07-26 15:21 +1000
  Re: Help Peter Otten <__peter__@web.de> - 2013-07-26 07:27 +0200
  Re: Help Chris Angelico <rosuav@gmail.com> - 2013-07-26 06:35 +0100
  Re: Help Terry Reedy <tjreedy@udel.edu> - 2013-07-26 01:46 -0400
  Re: Help tyler@familyrobbins.com - 2013-07-26 20:40 -0700

csiph-web