'str' 对象没有属性 'subs'
'str' object has not attribute 'subs'
这是我用 Vim 编写的 Python 代码。每当我 运行 它时,我都会收到错误 'str' object has not attribute 'subs'
from sympy import *
x,a_test,b_test,fa_test,fb_test=symbols('x a_test b_test fa_test fb_test')
expr=raw_input("enter the equation")
print expr
print "hello"
try:
print "hello"
inc=0
a=inc
fa=expr.subs(x,inc)
print "hello"
if(fa<0):
print "hello"
inc+=1
fb=expr.subs(x,inc)
if(fb<=0):
while(fb<=0):
inc+=1
else:
print "hello"
inc+=1
fb=expr.subs(x,inc)
if(fb<=0):
while(fb<=0):
inc+=1
b=inc
print a
print b
print fa
print fb
except Exception,e:
print e
raw_input
的return值是str
;你不能像使用 SymPy 一样使用它 expr
。您需要先 parse 它:
from sympy.parsing.sympy_parser import parse_expr
...
expr = parse_expr(raw_input("enter the equation"))
这是我用 Vim 编写的 Python 代码。每当我 运行 它时,我都会收到错误 'str' object has not attribute 'subs'
from sympy import *
x,a_test,b_test,fa_test,fb_test=symbols('x a_test b_test fa_test fb_test')
expr=raw_input("enter the equation")
print expr
print "hello"
try:
print "hello"
inc=0
a=inc
fa=expr.subs(x,inc)
print "hello"
if(fa<0):
print "hello"
inc+=1
fb=expr.subs(x,inc)
if(fb<=0):
while(fb<=0):
inc+=1
else:
print "hello"
inc+=1
fb=expr.subs(x,inc)
if(fb<=0):
while(fb<=0):
inc+=1
b=inc
print a
print b
print fa
print fb
except Exception,e:
print e
raw_input
的return值是str
;你不能像使用 SymPy 一样使用它 expr
。您需要先 parse 它:
from sympy.parsing.sympy_parser import parse_expr
...
expr = parse_expr(raw_input("enter the equation"))