使用Jupyter Notebook,我的代码曾经运行得很好,直到我决定在寻找二次方程式的根时,将虚数的输出以“ i”表示。 一个问题是:
from ipykernel import kernelapp as app
和
LookupError Traceback (most recent call last)
cell_name in async-def-wrapper()
cell_name in Noroots(a, b, c)
LookupError: unknown encoding: i
下面是代码。
import numpy as np
def equalroots(a,b,c):
print("There are two real and equal roots")
print("Since they are the same,we have one output")
print(((-b)+(np.sqrt((b**2)-(4*a*c))))/(2*a))
def differroots(a,b,c):
print("There are two real and distinct roots")
print("The roots are {:f} and {:f}".format(((-b)+(np.sqrt((b**2)-(4*a*c))))/(2*a),((b)+(np.sqrt((b**2)-(4*a*c))))/(2*a)))
def Noroots(a,b,c):
print("There are no real roots.Imaginary roots")
print(str(((-b)+(np.sqrt((b**2)-(4*a*c))))/(2*a)),"i and ",str(((b)+(np.sqrt((b**2)-(4*a*c))))/(2*a),"i"))
print("Please enter the function in cordination with a(x**2)+bx+c")
a=float(input("Please Input the value of a : "))
b=float(input("Please Input the value of b : "))
c=float(input("Please Input the value of c : "))
if (b**2)-(4*a*c)==0:
return(equalroots(a,b,c))
elif (b**2)-(4*a*c)>0:
return(differroots(a,b,c))
else:
return(Noroots(a,b,c))