eq = input() eq1 = eq.replace("=","-(") + ")" c = eval(eq1, {'X': 1j}) print(int(-c.real/c.imag))
For example: solve ( "x - 2x + 5x - 46 (235-24) = x + 2") Here to interpret the bar code. First, a first row (except INPUT ()), it has been modified equation, generated as a result of the formula 0 "x - 2x + 5x - 46 (235-24) - (x + 2)".
The second row is performed by this formula eval, and substituted into equation x = 1j, the result is -9708 + 3j.
Note that x = 1j, so this equation can be simplified as "-9708 + 3x = 0", as long as the - (--9708) / a x 3 can be obtained.
It is the real part of the complex -9708, and 3 is the imaginary part of the complex, then the result becomes "-c.real / c.imag".
Therefore it is clear that this function is not the solution of complex equations.