Python If Statement Defaults to an elif
- by Brad Carvalho
Not sure why my code is defaulting to this elif. But it's never getting to the else statement. Even going as far as throwing index out of bound errors in the last elif. Please disregard my non use of regex. It wasn't allowed for this homework assignment. The problem is the last elif before the else statement.
Cheers,
Brad
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.startswith('ADD'):
print 'Found ADD'
elif item.startswith('INC'):
print 'Found INC'
elif item.startswith('SUB'):
print 'Found SUB'
elif item.startswith('DEC'):
print 'Found DEC'
elif item.startswith('MUL'):
print 'Found MUL'
elif item.startswith('DIV'):
print 'Found DIV'
elif item.startswith('BEQ'):
print 'Found BEQ'
elif item.startswith('BLT'):
print 'Found BLT'
elif item.startswith('BR'):
print 'Found BR'
elif item.startswith('END'):
print 'Found END'
elif item.find(':') and item[(item.find(':') -1)].isalpha():
print 'Mya have found a label'
else:
print 'Not sure what I found'