【发布时间】:2012-09-16 03:09:18
【问题描述】:
不知道为什么我的代码默认使用这个 elif。但它永远不会到达 else 语句。甚至在最后一个 elif 中将索引抛出边界错误。
请忽略我不使用正则表达式。这个家庭作业不允许。问题是 else 语句之前的最后一个 elif。
if item == '':
print ("%s\n" % item).rstrip('\n')
elif item.startswith('MOVE') and not item.startswith('MOVEI'):
print 'Found MOVE'
elif item.startswith('MOVEI'):
print 'Found MOVEI'
elif item.startswith('BGT'):
print 'Found BGT'
# ...
elif item.find(':') and item[(item.find(':') -1)].isalpha():
print 'Mya have found a label'
else:
# Never get to this branch
print 'Not sure what I found'
【问题讨论】:
-
在发布 Python 代码时要注意缩进。
-
好点。我对此表示歉意。
-
您可以通过单击问题下方的“编辑”链接来修复它。
-
您正在验证的项目中的测试数据是什么?
标签: python