TheAlgorithms/Python · error · ValueError
Both a & b of two equations can't be zero.
Error message
Both a & b of two equations can't be zero.
What it means
Error "Both a & b of two equations can't be zero." thrown in TheAlgorithms/Python.
Source
Thrown at matrix/cramers_rule_2x2.py:59
>>> cramers_rule_2x2([0, 0, 6], [0, 0, 3])
Traceback (most recent call last):
...
ValueError: Both a & b of two equations can't be zero.
>>> cramers_rule_2x2([1, 2, 3], [1, 2, 3])
Traceback (most recent call last):
...
ValueError: Infinite solutions. (Consistent system)
>>> cramers_rule_2x2([0, 4, 50], [0, 3, 99])
Traceback (most recent call last):
...
ValueError: No solution. (Inconsistent system)
"""
# Check if the input is valid
if not len(equation1) == len(equation2) == 3:
raise ValueError("Please enter a valid equation.")
if equation1[0] == equation1[1] == equation2[0] == equation2[1] == 0:
raise ValueError("Both a & b of two equations can't be zero.")
# Extract the coefficients
a1, b1, c1 = equation1
a2, b2, c2 = equation2
# Calculate the determinants of the matrices
determinant = a1 * b2 - a2 * b1
determinant_x = c1 * b2 - c2 * b1
determinant_y = a1 * c2 - a2 * c1
# Check if the system of linear equations has a solution (using Cramer's rule)
if determinant == 0:
if determinant_x == determinant_y == 0:
raise ValueError("Infinite solutions. (Consistent system)")
else:
raise ValueError("No solution. (Inconsistent system)")
elif determinant_x == determinant_y == 0:
# Trivial solution (Inconsistent system)View on GitHub (pinned to f5988cc097)
Solutions
- Provide equations where at least one of a or b is non-zero in each equation.
When it happens
Trigger: Thrown at matrix/cramers_rule_2x2.py:59 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/b838f0b4df3e5d59.
Report an issue: GitHub.