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


Groups > comp.lang.python > #40579 > unrolled thread

Input wont work with if statement if it has a space

Started byeli m <techgeek201@gmail.com>
First post2013-03-05 15:31 -0800
Last post2013-03-05 17:50 -0800
Articles 5 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Input wont work with if statement if it has a space eli m <techgeek201@gmail.com> - 2013-03-05 15:31 -0800
    Re: Input wont work with if statement if it has a space eli m <techgeek201@gmail.com> - 2013-03-05 15:33 -0800
      Re: Input wont work with if statement if it has a space emile <emile@fenx.com> - 2013-03-05 15:47 -0800
        Re: Input wont work with if statement if it has a space eli m <techgeek201@gmail.com> - 2013-03-05 17:50 -0800
        Re: Input wont work with if statement if it has a space eli m <techgeek201@gmail.com> - 2013-03-05 17:50 -0800

#40579 — Input wont work with if statement if it has a space

Fromeli m <techgeek201@gmail.com>
Date2013-03-05 15:31 -0800
SubjectInput wont work with if statement if it has a space
Message-ID<f19881f0-8f12-42eb-a55a-49b858c9b50f@googlegroups.com>
Hi guys, i have a program like this: (A lot of code is not included)
run = 0
while run == 0:
   raw_input("Type in a function:")
   if function == "Example":
      print ("Hello World!")
   else:
      print ("blah blah blah")

The problem is that whenever i type in example with a space after it then it prints the else statement.

My question is, how do i get it to except input with spaces?

[toc] | [next] | [standalone]


#40580

Fromeli m <techgeek201@gmail.com>
Date2013-03-05 15:33 -0800
Message-ID<dbf70d62-0425-43c2-ab11-37dfdcccb458@googlegroups.com>
In reply to#40579
On Tuesday, March 5, 2013 3:31:13 PM UTC-8, eli m wrote:
> Hi guys, i have a program like this: (A lot of code is not included)
> 
> run = 0
> 
> while run == 0:
> 
>    raw_input("Type in a function:")
> 
>    if function == "Example":
> 
>       print ("Hello World!")
> 
>    else:
> 
>       print ("blah blah blah")
> 
> 
> 
> The problem is that whenever i type in example with a space after it then it prints the else statement.
> 
> 
> 
> My question is, how do i get it to except input with spaces?

oops i meant function = raw_input("Type in a function:")

[toc] | [prev] | [next] | [standalone]


#40583

Fromemile <emile@fenx.com>
Date2013-03-05 15:47 -0800
Message-ID<mailman.2916.1362527253.2939.python-list@python.org>
In reply to#40580
On 03/05/2013 03:33 PM, eli m wrote:
> On Tuesday, March 5, 2013 3:31:13 PM UTC-8, eli m wrote:
>> Hi guys, i have a program like this: (A lot of code is not included)
>>
>> run = 0
>>
>> while run == 0:
>>
>>     function = raw_input("Type in a function:")
>>
>>     if function == "Example":

whenever function isn't _exactly_ "Example" the else clause executes.

If you want to catch forms of example you might try:

     if function.strip().upper() == "EXAMPLE":

Emile




>>
>>        print ("Hello World!")
>>
>>     else:
>>
>>        print ("blah blah blah")
>>
>>
>>
>> The problem is that whenever i type in example with a space after it then it prints the else statement.
>>
>>
>>
>> My question is, how do i get it to except input with spaces?
>
> oops i meant function = raw_input("Type in a function:")
>

[toc] | [prev] | [next] | [standalone]


#40591

Fromeli m <techgeek201@gmail.com>
Date2013-03-05 17:50 -0800
Message-ID<71e39dc3-1b79-4331-9d4f-eb94c64068ce@googlegroups.com>
In reply to#40583
On Tuesday, March 5, 2013 3:47:31 PM UTC-8, emile wrote:
> On 03/05/2013 03:33 PM, eli m wrote:
> 
> > On Tuesday, March 5, 2013 3:31:13 PM UTC-8, eli m wrote:
> 
> >> Hi guys, i have a program like this: (A lot of code is not included)
> 
> >>
> 
> >> run = 0
> 
> >>
> 
> >> while run == 0:
> 
> >>
> 
> >>     function = raw_input("Type in a function:")
> 
> >>
> 
> >>     if function == "Example":
> 
> 
> 
> whenever function isn't _exactly_ "Example" the else clause executes.
> 
> 
> 
> If you want to catch forms of example you might try:
> 
> 
> 
>      if function.strip().upper() == "EXAMPLE":
> 
> 
> 
> Emile
> 
> 
> 
> 
> 
> 
> 
> 
> 
> >>
> 
> >>        print ("Hello World!")
> 
> >>
> 
> >>     else:
> 
> >>
> 
> >>        print ("blah blah blah")
> 
> >>
> 
> >>
> 
> >>
> 
> >> The problem is that whenever i type in example with a space after it then it prints the else statement.
> 
> >>
> 
> >>
> 
> >>
> 
> >> My question is, how do i get it to except input with spaces?
> 
> >
> 
> > oops i meant function = raw_input("Type in a function:")
> 
> >

Thank you!

[toc] | [prev] | [next] | [standalone]


#40592

Fromeli m <techgeek201@gmail.com>
Date2013-03-05 17:50 -0800
Message-ID<mailman.2920.1362534641.2939.python-list@python.org>
In reply to#40583
On Tuesday, March 5, 2013 3:47:31 PM UTC-8, emile wrote:
> On 03/05/2013 03:33 PM, eli m wrote:
> 
> > On Tuesday, March 5, 2013 3:31:13 PM UTC-8, eli m wrote:
> 
> >> Hi guys, i have a program like this: (A lot of code is not included)
> 
> >>
> 
> >> run = 0
> 
> >>
> 
> >> while run == 0:
> 
> >>
> 
> >>     function = raw_input("Type in a function:")
> 
> >>
> 
> >>     if function == "Example":
> 
> 
> 
> whenever function isn't _exactly_ "Example" the else clause executes.
> 
> 
> 
> If you want to catch forms of example you might try:
> 
> 
> 
>      if function.strip().upper() == "EXAMPLE":
> 
> 
> 
> Emile
> 
> 
> 
> 
> 
> 
> 
> 
> 
> >>
> 
> >>        print ("Hello World!")
> 
> >>
> 
> >>     else:
> 
> >>
> 
> >>        print ("blah blah blah")
> 
> >>
> 
> >>
> 
> >>
> 
> >> The problem is that whenever i type in example with a space after it then it prints the else statement.
> 
> >>
> 
> >>
> 
> >>
> 
> >> My question is, how do i get it to except input with spaces?
> 
> >
> 
> > oops i meant function = raw_input("Type in a function:")
> 
> >

Thank you!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web