Python Invalid syntax in elif

Your elif is not indented properly…it should be indented the same way if is indented. Seeing the else block, it seems that you have by mistake indented the first if. Remember that elif/else should be preceded by an if always.

EDIT: corresponding to the edited question details: Why is the second else there? It isn’t preceded by an if. I feel you need to get your conditions organized properly before writing the code.

One way to correct the code is to change this to an elif block:

else:
    count1 += 1
    if count1==1: a=line[0]
    elif count1==2: relation=line[0]
    elif count1==3: b=line[0]

You might want your indentation in Python to get better. Consider reading up a bit on that 🙂

Leave a Comment