Python 我在spyder:AttributeError:';int';对象没有属性';潜艇';

Python 我在spyder:AttributeError:';int';对象没有属性';潜艇';,python,python-2.7,sympy,attributeerror,Python,Python 2.7,Sympy,Attributeerror,准确地说,误差是: x2new= solve(n.subs(x1,0).subs(x3,0)) AttributeError: 'int' object has no attribute 'subs' 这是我的代码: from sympy import symbols, Eq, solve, sympify x, y, z= symbols('x y z') a= 6*x - 2*y + z - 11 b= -2*x + 7 *y + 2*z - 5 c= x + 2*y - 5*

准确地说,误差是:

x2new= solve(n.subs(x1,0).subs(x3,0))
AttributeError: 'int' object has no attribute 'subs'    
这是我的代码:

from sympy import symbols, Eq, solve, sympify

x, y, z= symbols('x y z')

a= 6*x - 2*y + z - 11
b= -2*x + 7 *y + 2*z - 5
c= x + 2*y - 5*z + 1

m=Eq(sympify(a))
n=Eq(sympify(b))
o=Eq(sympify(c))

x1=solve(m.subs(y,0).subs(z,0))
x2=solve(n.subs(x,0).subs(z,0))
x3=solve(o.subs(x,0).subs(y,0))

n= 2
for i in range(n):
    x1new= solve(m.subs(x2,0).subs(x3,0))
    x2new= solve(n.subs(x1,0).subs(x3,0))
    x3new= solve(o.subs(x1,0).subs(x2,0))
    
    x1= x1new
    x2= x2new
    x3= x3new
    i= i+1
    
    print(x1new)
    print(x2new)
    print(x3new)

它抱怨是因为它需要的是
SymPy
数字,而不是内置的python
int

如果仔细查看代码,您会注意到您意外地覆盖了变量
n

n=Eq(sympify(b))
n= 2

如果您只是重命名for循环计数器变量,它将正常工作:

from sympy import symbols, Eq, solve, sympify, Integer

x, y, z= symbols('x y z')

a= 6*x - 2*y + z - 11
b= -2*x + 7 *y + 2*z - 5
c= x + 2*y - 5*z + 1

m=Eq(sympify(a), 0)
n=Eq(sympify(b), 0)
o=Eq(sympify(c), 0)

x1=solve(m.subs(y,0).subs(z,0))
x2=solve(n.subs(x,0).subs(z,0))
x3=solve(o.subs(x,0).subs(y,0))

counter = 2
for i in range(counter):
    x1new= solve(m.subs(x2,0).subs(x3,0))
    x2new= solve(n.subs(x1,0).subs(x3,0))
    x3new= solve(o.subs(x1,0).subs(x2,0))
    
    x1= x1new
    x2= x2new
    x3= x3new
    i= i+1
    
    print(x1new)
    print(x2new)
    print(x3new)
其结果是:

[{x: y/3 - z/6 + 11/6}]
[{x: 7*y/2 + z - 5/2}]
[{x: -2*y + 5*z - 1}]
[{x: y/3 - z/6 + 11/6}]
[{x: 7*y/2 + z - 5/2}]
[{x: -2*y + 5*z - 1}]

我完全错过了。它正在工作!