当我运行此代码时:
from sympy import *
x = symbols('x')
equation = "x + 2"
var = solve(Eq(equation, 5), x)
print(var)
我遇到了一个大错误。
请帮助
答案 0 :(得分:0)
尝试
from sympy import *
x = Symbol('x')
equation = x + 2
var = solve(Eq(equation, 5), x)
print(var)
我在计算机上得到[3]的结果。您的也应该工作!
答案 1 :(得分:0)
安装软件包:
sudo pip install sympy
解决方案
from sympy import *
x = symbols('x')
equation = x + 2
var = solve(Eq(equation, 5), x)
print(var)
输出:[3]
答案 2 :(得分:0)
请勿将方程式用引号引起来。 工作示例:
from sympy import *
x = Symbol('x')
equation = Eq(x+2, 5)
answer = solve(equation,x)
print(answer)
输出[3]
答案 3 :(得分:0)
如果要使用字符集,这是另一种解决方案。
from sympy import *
x = Symbol('x')
equation = 'x + 2'
sympy_eq = sympify("Eq(" + equation + ",5)")
var = solveset(sympy_eq,x)
print(var)