Error in or

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Error in or

subhabrata.banerji@gmail.com
Dear Group,

In the following script,

  inp1=raw_input("PRINT YOUR INPUT:")
  if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1):
 
  if write this it is working fine, but if I write
   
  if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
 
 the portion of (''' " ''' in   inp1) is not working.

If any one of the esteemed members may kindly suggest the error I am making.

I am using Python2.7+ on Windows 7 Professional.

Apology for any indentation error.

Regards,
Subhabrata Banerjee.
         

Reply | Threaded
Open this post in threaded view
|

Error in or

Ian Kelly-2
On Thu, Jun 11, 2015 at 9:40 AM,  <subhabrata.banerji at gmail.com> wrote:
>   if write this it is working fine, but if I write
>
>   if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
>
>  the portion of (''' " ''' in   inp1) is not working.

Not working how? I copy-pasted the line and it appears to work fine.

Reply | Threaded
Open this post in threaded view
|

Error in or

subhabrata.banerji@gmail.com
In reply to this post by subhabrata.banerji@gmail.com
On Thursday, June 11, 2015 at 9:20:59 PM UTC+5:30, Ian wrote:
> On Thu, Jun 11, 2015 at 9:40 AM,  
> >   if write this it is working fine, but if I write
> >
> >   if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
> >
> >  the portion of (''' " ''' in   inp1) is not working.
>
> Not working how? I copy-pasted the line and it appears to work fine.

Dear Sir,
Thank you for your kind reply. Nice to know your reply, but I am trying to send you my experiment, please see my results,

>>> def input1(n):
        inp1=raw_input("PRINT YOUR QUERY:")
        if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
                print "FINE"

               
>>> input1(1)
PRINT YOUR QUERY:"Java"
>>> input1(1)
PRINT YOUR QUERY:"Obama in London"
>>> input1(1)
PRINT YOUR QUERY:Obama AND Bush
FINE
>>> input1(1)
PRINT YOUR QUERY:Obama OR Bush
FINE
>>>

you may get better my problem.

Regards,
Subhabrata Banerjee.

Reply | Threaded
Open this post in threaded view
|

Error in or

Ian Kelly-2
On Thu, Jun 11, 2015 at 10:39 AM,  <subhabrata.banerji at gmail.com> wrote:

> On Thursday, June 11, 2015 at 9:20:59 PM UTC+5:30, Ian wrote:
>> On Thu, Jun 11, 2015 at 9:40 AM,
>> >   if write this it is working fine, but if I write
>> >
>> >   if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
>> >
>> >  the portion of (''' " ''' in   inp1) is not working.
>>
>> Not working how? I copy-pasted the line and it appears to work fine.
>
> Dear Sir,
> Thank you for your kind reply. Nice to know your reply, but I am trying to send you my experiment, please see my results,
>
>>>> def input1(n):
>         inp1=raw_input("PRINT YOUR QUERY:")
>         if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
>                 print "FINE"
>
>
>>>> input1(1)
> PRINT YOUR QUERY:"Java"
>>>> input1(1)
> PRINT YOUR QUERY:"Obama in London"
>>>> input1(1)
> PRINT YOUR QUERY:Obama AND Bush
> FINE
>>>> input1(1)
> PRINT YOUR QUERY:Obama OR Bush
> FINE
>>>>
>
> you may get better my problem.

The substring that you're looking for has spaces around the " symbol.
The example inputs that you gave don't have spaces around the "
symbols, so they don't contain the substring.  The triple quotes are
also unnecessary, though harmless -- it's not a multiline string, and
there are no ' symbols to escape in the string. Try replacing the
substring with just this: '"'.

Reply | Threaded
Open this post in threaded view
|

Error in or

subhabrata.banerji@gmail.com
In reply to this post by subhabrata.banerji@gmail.com
On Thursday, June 11, 2015 at 10:18:33 PM UTC+5:30, Ian wrote:

> On Thu, Jun 11, 2015 at 10:39 AM,   wrote:
> > On Thursday, June 11, 2015 at 9:20:59 PM UTC+5:30, Ian wrote:
> >> On Thu, Jun 11, 2015 at 9:40 AM,
> >> >   if write this it is working fine, but if I write
> >> >
> >> >   if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
> >> >
> >> >  the portion of (''' " ''' in   inp1) is not working.
> >>
> >> Not working how? I copy-pasted the line and it appears to work fine.
> >
> > Dear Sir,
> > Thank you for your kind reply. Nice to know your reply, but I am trying to send you my experiment, please see my results,
> >
> >>>> def input1(n):
> >         inp1=raw_input("PRINT YOUR QUERY:")
> >         if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
> >                 print "FINE"
> >
> >
> >>>> input1(1)
> > PRINT YOUR QUERY:"Java"
> >>>> input1(1)
> > PRINT YOUR QUERY:"Obama in London"
> >>>> input1(1)
> > PRINT YOUR QUERY:Obama AND Bush
> > FINE
> >>>> input1(1)
> > PRINT YOUR QUERY:Obama OR Bush
> > FINE
> >>>>
> >
> > you may get better my problem.
>
> The substring that you're looking for has spaces around the " symbol.
> The example inputs that you gave don't have spaces around the "
> symbols, so they don't contain the substring.  The triple quotes are
> also unnecessary, though harmless -- it's not a multiline string, and
> there are no ' symbols to escape in the string. Try replacing the
> substring with just this: '"'.

Dear Sir,
Thank you. It seems working.
Regards,
Subhabrata Banerjee.

Reply | Threaded
Open this post in threaded view
|

Error in or

Mark Lawrence
In reply to this post by subhabrata.banerji@gmail.com
On 11/06/2015 17:39, subhabrata.banerji at gmail.com wrote:

> On Thursday, June 11, 2015 at 9:20:59 PM UTC+5:30, Ian wrote:
>> On Thu, Jun 11, 2015 at 9:40 AM,
>>>    if write this it is working fine, but if I write
>>>
>>>    if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
>>>
>>>   the portion of (''' " ''' in   inp1) is not working.
>>
>> Not working how? I copy-pasted the line and it appears to work fine.
>
> Dear Sir,
> Thank you for your kind reply. Nice to know your reply, but I am trying to send you my experiment, please see my results,
>
>>>> def input1(n):
> inp1=raw_input("PRINT YOUR QUERY:")
> if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
> print "FINE"
>
>
>>>> input1(1)
> PRINT YOUR QUERY:"Java"
>>>> input1(1)
> PRINT YOUR QUERY:"Obama in London"
>>>> input1(1)
> PRINT YOUR QUERY:Obama AND Bush
> FINE
>>>> input1(1)
> PRINT YOUR QUERY:Obama OR Bush
> FINE
>>>>
>
> you may get better my problem.
>
> Regards,
> Subhabrata Banerjee.
>

In [6]: input1(1)
PRINT YOUR QUERY:Bush ANDES Obama
FINE

In [8]: input1(1)
PRINT YOUR QUERY:Bush ORDER Obama
FINE

Do you actually want this?

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


Reply | Threaded
Open this post in threaded view
|

Error in or

Steven D'Aprano-11
In reply to this post by subhabrata.banerji@gmail.com
On Thu, 11 Jun 2015 08:40:50 -0700, subhabrata.banerji wrote:

>   if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in
>   inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*"
>   in inp1) or (''' " ''' in   inp1):

This is better written as:

    if any(substr in inp1 for substr in
           ['AND', 'OR', 'NOT', '>', '&', 'MAYBE', '(', '*', ' " ']):
        print 'FINE'


--
Steve

Reply | Threaded
Open this post in threaded view
|

Error in or

Marko Rauhamaa
Steven D'Aprano <steve+comp.lang.python at pearwood.info>:

> This is better written as:
>
>     if any(substr in inp1 for substr in
>            ['AND', 'OR', 'NOT', '>', '&', 'MAYBE', '(', '*', ' " ']):
>         print 'FINE'

Or, equivalently:

   for substr in ['AND', 'OR', 'NOT', '>', '&', 'MAYBE', '(', '*', ' " ']:
       if substr in inp1:
           print('FINE')
           break


Marko