Your if
condition is evaluated as:
if (InputKey[0][0] == 1) or 2:
which is equivalent to:
if (InputKey[0][0] == 1) or True:
which will always evaluated to True
.
You should use:
if InputKey[0][0] == 1 or InputKey[0][0] == 2:
or
if InputKey[0][0] in (1, 2):
Note that, if your InputKey[0][0]
is of type string
, you can convert it to int
using int(InputType[0][0])
, else it won't match with 1
or 2
.
Apart from that, your for
loop can be modified as:
for line in input_key.readlines():
# You don't need list comprehension. `line.split()` itself gives a list
InputKey.append(line.split())