{"record":{"id":"d30af46710e918ab","repo":"TheAlgorithms/Python","slug":"solve-simultaneous-requires-lists-of-integers","errorCode":null,"errorMessage":"solve_simultaneous() requires lists of integers","messagePattern":"solve_simultaneous\\(\\) requires lists of integers","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/simultaneous_linear_equation_solver.py","lineNumber":87,"sourceCode":"        ...\r\n    IndexError: solve_simultaneous() requires n lists of length n+1\r\n    >>> solve_simultaneous([[1, 2, 3],[\"a\", 7, 8]])\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: solve_simultaneous() requires lists of integers\r\n    >>> solve_simultaneous([[0, 2, 3],[4, 0, 6]])\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: solve_simultaneous() requires at least 1 full equation\r\n    \"\"\"\r\n    if len(equations) == 0:\r\n        raise IndexError(\"solve_simultaneous() requires n lists of length n+1\")\r\n    _length = len(equations) + 1\r\n    if any(len(item) != _length for item in equations):\r\n        raise IndexError(\"solve_simultaneous() requires n lists of length n+1\")\r\n    for row in equations:\r\n        if any(not isinstance(column, (int, float)) for column in row):\r\n            raise ValueError(\"solve_simultaneous() requires lists of integers\")\r\n    if len(equations) == 1:\r\n        return [equations[0][-1] / equations[0][0]]\r\n    data_set = equations.copy()\r\n    if any(0 in row for row in data_set):\r\n        temp_data = data_set.copy()\r\n        full_row = []\r\n        for row_index, row in enumerate(temp_data):\r\n            if 0 not in row:\r\n                full_row = data_set.pop(row_index)\r\n                break\r\n        if not full_row:\r\n            raise ValueError(\"solve_simultaneous() requires at least 1 full equation\")\r\n        data_set.insert(0, full_row)\r\n    useable_form = data_set.copy()\r\n    simplified = simplify(useable_form)\r\n    simplified = simplified[::-1]\r\n    solutions: list = []\r\n    for row in simplified:\r","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/simultaneous_linear_equation_solver.py#L69-L105","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","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"],"exampleFix":"# before\nrows = [line.split(',') for line in text.splitlines()]\nsolve_simultaneous(rows)  # strings -> ValueError\n\n# after\nrows = [[float(x) for x in line.split(',')] for line in text.splitlines()]\nsolve_simultaneous(rows)","handlingStrategy":"type-guard","validationCode":"equations = [[float(x) for x in row] for row in equations]\nsolve_simultaneous(equations)","typeGuard":"def is_numeric_system(eq: list) -> bool:\n    return all(\n        isinstance(x, (int, float)) and not isinstance(x, bool)\n        for row in eq for x in row\n    )","tryCatchPattern":"try:\n    solve_simultaneous(equations)\nexcept ValueError as e:\n    if 'lists of integers' in str(e):\n        equations = [[float(x) for x in row] for row in equations]","preventionTips":["str.split() yields strings — always convert","JSON numbers may arrive as strings; coerce at load time","Decimal/Fraction are rejected; convert to float first"],"tags":["python","math","linear-algebra","type-check","value-error"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}