← Back to challenges

First-Degree Equation

PythonHardalgebramathalgorithms

Instructions

Create a function that takes a first-degree equation as a string and solves it. If there would be more than one solution, the function must return "Infinite solutions".

Examples

solver("2*x + 1 = x") ➞ -1.0

solver("7*x + x - 4 = 0") ➞ 0.5

solver("x = x") ➞ "Infinite solutions"

Notes

The given variable is always "x".

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.