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
- How do I copy a file in Python?
- Use Gif Logo For Loading Screen In Kivy
- beyond top level package error in relative import
- How can I sort a dictionary by key?
- How do you append to a file?
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- Jupyter Notebook not saving: ‘_xsrf’ argument missing from post
- What does it mean to have an index to scalar variable error? python
- Could not install packages due to an EnvironmentError:
- What does “e” in “1e-5” in Python language mean and what is the name of this notation?
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- ‘Conda’ is not recognized as internal or external command
- pip/python: normal site-packages is not writeable
- Convert DataFrame column type from string to datetime, dd/mm/yyyy format
- How can I remove a trailing newline?
- Is there a list of line styles in matplotlib?
- Import urllib.request, ImportError: No module named request
- TypeError: cannot convert the series to
- Spark RDD to DataFrame python
- index 1 is out of bounds for axis 0 with size 1
- How can I time a code segment for testing performance with Pythons timeit?
- Python: tuple indices must be integers, not str when selecting from mysql table
- AttributeError: ‘list’ object has no attribute ‘replace’
- Countdown timer in Pygame
- Python [Errno 98] Address already in use
- Creating a dictionary from a csv file?
- How can I check for NaN values?
- Bad operand type for unary +: ‘str’
- How do I get the parent directory in Python?
- How to fix: “UnicodeDecodeError: ‘ascii’ codec can’t decode byte”
- How to read a text file into a list or an array with Python
- Map to List error: Series object not callable
- How to convert ‘binary string’ to normal string in Python3?
- What is the meaning of curly braces?
- Copy a list of list by value and not reference
- How do I print bold text in Python?
- python3 TypeError: ‘function’ object is not iterable
- pip connection failure: cannot fetch index base URL http://pypi.python.org/simple/
- Moving average or running mean
- Python 3.6 No module named pip
- Difference between import tkinter as tk and from tkinter import
- Split function add: \xef\xbb\xbf…\n to my list
- ImportError in importing from sklearn: cannot import name check_build
- Root mean square of a function in python
- Installing opencv on Windows 10 with python 3.6 and anaconda 3.6
- What is an easy way to implement fprintf in python?
- What is the recommended way to use Vim folding for Python code
- Plotting a python dict in order of key values
- How to normalize a NumPy array to within a certain range?
- How to check if a user is logged in (how to properly use user.is_authenticated)?
- Can I remove script tags with BeautifulSoup?
- Python ‘while’ with two conditions: “and” or “or”
- How to pass a list by reference?
- Python Quicksort Runtime Error: Maximum Recursion Depth Exceeded in cmp
- “for loop” with two variables?
- Python webbrowser.open() to open Chrome browser
- Flatten nested dictionaries, compressing keys
- Sending posts from Python to WordPress
- Update post / page using API + python