n = [1, 7, 14, 16,19]
x = raw_input()
if x in n:
print "match"
else:
print "no match"
How can I get this to work correctly ?
Solved! Go to Solution.
Raw_input is python 2.7, it has been replaced with 'input' in python 3.x, so substitute as needed.
The reason why it isn't working is that the return value is always a string, and you are trying to see if it is within a list of numbers.... note the type conversion in the following example.
a = [1, 2, 3, 4]
x = input('input please ') # raw_input in python 2.7
input please 1 # here I put in a number 1
x # to confirm
'1' # but it is a string... what to due
if int(x) in a: # a type conversion perhaps
print(True)
else:
print(False)
True # all is good
Raw_input is python 2.7, it has been replaced with 'input' in python 3.x, so substitute as needed.
The reason why it isn't working is that the return value is always a string, and you are trying to see if it is within a list of numbers.... note the type conversion in the following example.
a = [1, 2, 3, 4]
x = input('input please ') # raw_input in python 2.7
input please 1 # here I put in a number 1
x # to confirm
'1' # but it is a string... what to due
if int(x) in a: # a type conversion perhaps
print(True)
else:
print(False)
True # all is good
Thanks, it works perfect now.
I don't know why I missed that.
Now to try and figure out a way to save this as standalone tool.