问题如下:比如输入“x^3+2*x^2+1"
得到的是”3*x^2+4*x"
输入输出都应该是字符串ge'shi
class duoxiangshi():
def __init__(self,geshi):
self.geshi=geshi
def get_diff(self):
from sympy import diff,symbols
x=symbols('x')
tmp=self.geshi
tmp=tmp.replace("^","**")
y=tmp
res=str(diff(y,x))
return res.replace("**","^")
test=duoxiangsi("x^3+2*x^2+1")
d=test.get_diff()
print(d)
class duoxiangshi():
def __init__(self,geshi):
self.geshi=geshi
def get_diff(self):
from sympy import diff,symbols
x=symbols('x')
tmp=self.geshi
tmp=tmp.replace("^","**")
y=tmp
res=str(diff(y,x))
return res.replace("**","^")
test=duoxiangsi("x^3+2*x^2+1")
d=test.get_diff()
print(d)