擅长:python、mysql、java
<p>试试这个。我建议对变量使用较短的名称。您可以将“import numpy as np”替换为“import cmath”并替换np.lib.scimath软件如果您还没有安装numpy,请使用“cmath”。QES代表二次方程求解器。你知道吗</p>
<pre><code>#Import package
import numpy as np
#Define a new function called qes
def qes(a1,b1,c1):
ans1=((-1*b1)+np.lib.scimath.sqrt((b1**2)-(4*a1*c1)))/(2*a1)
ans2=((-1*b1)-np.lib.scimath.sqrt((b1**2)-(4*a1*c1)))/(2*a1)
return ans1,ans2
#With the defined function perform a calculation and print the answer
ans1,ans2=qes(1,2,1)
print('Answer 1 is: ',ans1,' Answer 2 is: ',ans2)
</code></pre>