Invalid syntax python elif

Closed.

You watching: Invalid syntax python elif

This question is not reproducible or was caused by typos. It is not presently accepting answers.
Want to boost this question? Upday the question so it's on-topic for Stack Overcirculation.

Closed 7 years earlier.


The code below shows in invlid syntax in the initially elif statement. I have checked and also rechecked my code several times, but cant number out just how to resolve the error.

See more: List Words With Silver In Them, Words Containing Silver

fileHandle = open ( "gra1.txt" )count=0count1=0fileList = fileHandle.readlines()for fileLine in fileList: line=fileLine.split() if line<0> == "0": print "graph G%d ", (count) count +=1 elif line<0> == "1": print " " elif line<0>=="": proceed else: count1 += 1 if count1==1: a=line<0> elif count1==2: relation=line<0> elif count1==3: b=line<0> else: print a, relation, b count1=0fileHandle.close()

*

Your elif is not indented correctly...it should be indented the same means if is indented. Seeing the else block, it appears that you have by mistake indented the first if. Remember that elif/else should be preyielded by an if constantly.

EDIT: corresponding to the edited question details: Why is the second else there? It isn"t predelivered by an if. I feel you should acquire your problems organized appropriately prior to composing the code.

One way to correct the code is to readjust 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 could want your indentation in Python to acquire better. Consider analysis up a little on that :-)


*

if line<0> == "0": print "graph G%d { ", (count) count +=1elif line<0> == "1":It appears that you accidentally missplaced your initially elif. In that state it matches no if"s so you obtain an error.


*

Not the answer you're looking for? Browse other inquiries tagged python if-statement syntax-error or ask your very own question.


*

website architecture / logo © 2021 Stack Exreadjust Inc; user contributions licensed under cc by-sa. rev2021.8.18.40012


Stack Overcirculation functions ideal with JavaScript enabled
*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange have the right to save cookies on your gadget and discshed information in accordance via our Cookie Policy.