Home > database >  Why does this sympy function return an empty list as an answer?
Why does this sympy function return an empty list as an answer?

Time:03-09

I am trying to solve this equation for x with python.

x - 1 = 99

I have this code, which should solve this.

This code is the minimum code I could find to reproduce the issue.

from sympy import Symbol,solve
x = Symbol('x',real=True)
eq = x-1==99
answer = solve(eq,x)
print(answer)

When I run the code, it returns this.

[]

The answer I am looking for is 100.

There are no error messages, and I have x set as a real number, so I do not understand why it returns this.

Could someone help?

CodePudding user response:

Maybe this can help?

from sympy import solveset
from sympy import Symbol, Eq
x = Symbol('x')
solveset(Eq(x-1, 99), x)

CodePudding user response:

I'm not very familiar with SymPy, but just looking at the docs on solving algebraic equations, it says "We suppose all equations are equaled to 0". Also, if you print eq from your code, you'll see that it's False, not an equation.

So simply move the 99 to the other side of the equals sign:

eq = x-1 - 99

Answer: [100]

  • Related