TheAlgorithms/Python · error · ValueError
solve_simultaneous() requires lists of integers
Error message
solve_simultaneous() requires lists of integers
What it means
Raised by solve_simultaneous() when any element of any equation row is not an int or float — e.g. a string like 'a', None, or a Decimal. Despite the message saying 'lists of integers', floats are accepted; only non-numeric types are rejected. This guard runs after the shape check, so a shape error masks it for malformed rows.
Source
Thrown at maths/simultaneous_linear_equation_solver.py:87
...
IndexError: solve_simultaneous() requires n lists of length n+1
>>> solve_simultaneous([[1, 2, 3],["a", 7, 8]])
Traceback (most recent call last):
...
ValueError: solve_simultaneous() requires lists of integers
>>> solve_simultaneous([[0, 2, 3],[4, 0, 6]])
Traceback (most recent call last):
...
ValueError: solve_simultaneous() requires at least 1 full equation
"""
if len(equations) == 0:
raise IndexError("solve_simultaneous() requires n lists of length n+1")
_length = len(equations) + 1
if any(len(item) != _length for item in equations):
raise IndexError("solve_simultaneous() requires n lists of length n+1")
for row in equations:
if any(not isinstance(column, (int, float)) for column in row):
raise ValueError("solve_simultaneous() requires lists of integers")
if len(equations) == 1:
return [equations[0][-1] / equations[0][0]]
data_set = equations.copy()
if any(0 in row for row in data_set):
temp_data = data_set.copy()
full_row = []
for row_index, row in enumerate(temp_data):
if 0 not in row:
full_row = data_set.pop(row_index)
break
if not full_row:
raise ValueError("solve_simultaneous() requires at least 1 full equation")
data_set.insert(0, full_row)
useable_form = data_set.copy()
simplified = simplify(useable_form)
simplified = simplified[::-1]
solutions: list = []
for row in simplified:
View on GitHub (pinned to f5988cc097)
Solutions
- Convert every element: [[float(x) for x in row] for row in equations]
- Convert Decimal/Fraction values to float before calling
- Validate numerics at parse time, not at solve time
Example fix
# before
rows = [line.split(',') for line in text.splitlines()]
solve_simultaneous(rows) # strings -> ValueError
# after
rows = [[float(x) for x in line.split(',')] for line in text.splitlines()]
solve_simultaneous(rows) Defensive patterns
Strategy: type-guard
Validate before calling
equations = [[float(x) for x in row] for row in equations] solve_simultaneous(equations)
Type guard
def is_numeric_system(eq: list) -> bool:
return all(
isinstance(x, (int, float)) and not isinstance(x, bool)
for row in eq for x in row
) Try / catch
try:
solve_simultaneous(equations)
except ValueError as e:
if 'lists of integers' in str(e):
equations = [[float(x) for x in row] for row in equations] Prevention
- str.split() yields strings — always convert
- JSON numbers may arrive as strings; coerce at load time
- Decimal/Fraction are rejected; convert to float first
When it happens
Trigger: Calling solve_simultaneous([[1, 2, 3], ['a', 7, 8]]). Very common when rows come from str.split() without int()/float() conversion — split yields strings even for '1'.
Common situations: Parsing equations from text files or stdin; rows coming from JSON with stringified numbers ('2' instead of 2); None placeholders for missing coefficients; mixing numpy scalars is fine (they subclass float/int) but Decimal and Fraction are NOT accepted and will raise.
Related errors
- Input series is not valid, valid series - [1, 2/3, 2]
- Input series is not valid, valid series - [2, 4, 6]
- solve_simultaneous() requires at least 1 full equation
- area_reg_polygon() only accepts integers greater than or equ
- Input list must be a non empty list
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/d30af46710e918ab.
Report an issue: GitHub.