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 🙂
Related Posts:
- Why does python use ‘else’ after for and while loops?
- Don’t understand this SyntaxError: illegal target for annotation
- Pig Latin Translator
- How to define a two-dimensional array?
- ‘Syntax Error: invalid syntax’ for no apparent reason
- Python’s equivalent of && (logical-and) in an if-statement
- Is double square brackets [[ ]] preferable over single square brackets [ ] in Bash?
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- Putting a simple if-then-else statement on one line [duplicate]
- How to write inline if statement for print?
- “If not” condition statement in python
- Python inline if statement
- if else in a list comprehension
- syntax error when using command line in python
- if else in a list comprehension
- syntax error when using command line in python
- SyntaxError: multiple statements found while compiling a single statement
- SyntaxError: multiple statements found while compiling a single statement
- How to exit a loop in Python?
- Python 3.6.0 syntax error “Missing parentheses in call to ‘print’ [duplicate]
- Python’s equivalent of && (logical-and) in an if-statement
- Python: SyntaxError: keyword can’t be an expression
- Pythonic way to combine FOR loop and IF statement
- SyntaxError: cannot assign to operator
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- excel IF formula Error, “You’ve entered too many arguments”
- If vs. else if vs. else statements?
- Checking whether pip is installed?
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- Required: Variable Found: Value
- Python: cannot concatenate ‘str’ and ‘int’ objects error
- if else construction
- Using if-else in JSP
- ternary operator in matlab
- if else function in pandas dataframe
- In python, how can I print lines that do NOT contain a certain string, rather than print lines which DO contain a certain string:
- Styling multi-line conditions in ‘if’ statements?
- Batch – If, ElseIf, Else
- While else statement equivalent for Java?
- Compare two columns using pandas
- if else statement in AngularJS templates
- SyntaxError: unexpected EOF while parsing
- How do I lowercase a string in Python?
- How do I copy a file in Python?
- How can I reverse a list in Python?
- Manually raising (throwing) an exception in Python
- How do I copy a file in Python?
- can’t multiply sequence by non-int of type ‘float’
- Difference between del, remove, and pop on lists
- How can I reverse a list in Python?
- How to use the pass statement
- How to use filter, map, and reduce in Python 3
- What does enumerate() mean?
- Searching the student-t distribution table for values using python
- How to declare an array in Python?
- Does Python have a ternary conditional operator?
- Use Gif Logo For Loading Screen In Kivy
- Praw & Discord.py: The bot keep sending the same meme. I want the bot to send different meme whenever it is asked
- What is the difference between Python’s list methods append and extend?
- How can I make a time delay in Python? [duplicate]
- Python – TypeError: ‘int’ object is not iterable
- TypeError: ‘int’ object is not subscriptable
- sphinx.ext.autodoc: Keeping names of constants in signature
- are there dictionaries in javascript like python?
- How do you round UP a number?
- Understanding slice notation
- Iterating over dictionaries using ‘for’ loops
- how to sort pandas dataframe from one column
- Why am I seeing “TypeError: string indices must be integers”?
- Understanding the main method of python [duplicate]
- How do you round UP a number?
- Understanding slice notation
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How do I update\upgrade pip itself from inside my virtual environment?
- How to open a file using the open with statement
- How to emulate a do-while loop?
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How do I update\upgrade pip itself from inside my virtual environment?
- How to comment out a block of code in Python [duplicate]
- Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)
- Using “with open() as file” method, how to write more than once? [duplicate]
- TypeError: list indices must be integers or slices, not str
- Why there is no do while loop in python
- How do I get a substring of a string in Python?
- How do I sort a dictionary by value?
- ImportError: DLL load failed: The specified module could not be found
- How do I sort a dictionary by value?
- How to prettyprint a JSON file?
- What does the “yield” keyword do?
- && (AND) and || (OR) in IF statements
- ImportError: DLL load failed: The specified module could not be found
- Replacements for switch statement in Python?
- How to install pip with Python 3?
- What is the difference between rw+ and r+
- What does ** (double star/asterisk) and * (star/asterisk) do for parameters?
- Is there a way to create multiline comments in Python?
- ‘pip’ is not recognized as an internal or external command
- Renaming column names in Pandas
- How to reset index in a pandas dataframe? [duplicate]
- pip not recognised as an internal or external command