如何正确显示sympy输出

2024-06-10 16:48:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我对用Python编码和使用django非常陌生。你知道吗

我的问题是:有没有可能得到我以前计算得到的输出的输入格式?例如,如果我得到一个像x**2的输出,我怎么能自动得到x^2(x上标2)?你知道吗

例如:i want this type of output.

def home(request):
    return render(request, 'home.html', {'name':"suchit"})

def add(request):
    sp.init_printing(use_latex=True)
    val1 = sp.symbols('val1')
    x = sp.symbols('x')
    val1 = (request.POST['num1'])
    # val2 = int(request.POST['num2'])
    # red = add('val1','val2')
    # init_printing()
    Differentiate = sp.diff(val1,x)
    Integrate = sp.integrate(val1,x)

    # result = [Differentiate,Integrate]
     # integral_steps(res)
    return render(request,'home.html',{'result': Differentiate, 'result1':  Integrate  })

    # return render(request, 'home.html ', {'name': 'add'})

输出为:-

x**2/2

我不想看到这种类型的输出。我想要x上标2/2(x^2/2)。选中链接以显示该格式。你知道吗


Tags: nameaddhomereturninitrequestdefhtml