Boolean Operator Confusion

subhabrata.banerji at subhabrata.banerji at
Fri Apr 24 16:50:11 CEST 2015

Dear Group,

I am trying to understand the use of Boolean operator in Python. I am trying to 
write small piece of script, as follows,

def input_test():
	str1=raw_input("PRINT QUERY:")
	if "AND" or "OR" or "NOT" in str1:
		print "It is a Boolean Query"
	elif "AND" or "OR" or "NOT" not in str1:
		print "It is not a Boolean Query"
		print "None"

I am trying to achieve if the words "AND","OR","NOT" ... in string I want to recognize it as,
Boolean Query, if they are not there the string is not Boolean query. 
As I am trying to test it I am getting following output,

>>> input_test()
PRINT QUERY:obama AND clinton
It is a Boolean Query
>>> input_test()
PRINT QUERY:obama clinton
It is a Boolean Query

To understand Boolean operators I have tried to read the follwing link,

and practised script like the following:
>>> def currency(n):
	x1=raw_input("PRINT Your Country")
	x2=raw_input("Print Your Currency")
	if x1=="USA" and x2=="Dollar":
		print "Correct"
	elif x1=="USA" and x2!="Dollar":
		print "Not Matching"
		print "None"

>>> currency(1)
PRINT Your CountryUSA
Print Your CurrencyDollar

But I am doing something wrong. If anybody may kindly suggest.

Subhabrata Banerjee.

More information about the Python-list mailing list