#C14338. Solve a Simple Linear Equation
Solve a Simple Linear Equation
Solve a Simple Linear Equation
You are given a linear equation in one variable x of the form $ax+b=c$, where a, b, and c are real numbers. Your task is to solve for x and print its value rounded to 2 decimal places. If the equation is invalid or does not have a unique solution (for example, when a=0 leading to no or infinitely many solutions), then output None
.
The input equation may include extraneous spaces which should be ignored. Note that the coefficient a might be omitted if it is 1 or -1 (e.g., x
or -x
).
inputFormat
The input consists of a single line from stdin which contains the linear equation in the form ax+b=c. Spaces may appear arbitrarily in the equation.
outputFormat
Print the value of x rounded to 2 decimal places to stdout if a unique solution exists; otherwise, print None
.
3x + 2 = 14
4.0
</p>