【发布时间】:2013-07-21 07:34:42
【问题描述】:
我试图做出这样的条件,如果数组中的 [0][0] 条目不等于 1 或 2,则程序会打印一条错误消息。我无法让它工作,我知道这是因为我无法让逻辑正确。
try:
with open(input_script) as input_key:
for line in input_key.readlines():
x=[item for item in line.split()]
InputKey.append(x)
if InputKey[0][0] == 1 or 2: #This is where my condition is being tested.
print '.inp file succesfully imported' #This is where my success (or fail) print comes out.
else:
print 'failed'
except IOError:
print '.inp file import unsuccessful. Check that your file-path is valid.'
【问题讨论】:
标签: python if-statement boolean boolean-expression