下面的代碼是我用於二次問題求解器的地方,其中a不能等於0.我目前得到了非常奇怪的答案,並且似乎無法找出問題所在。思考?二次方程的問題
def descriminant(a, b, c): #Setting input perameters for descriminant
if a>0 or a<0: #If a isnt equal to 0, find descriminant
disc = (b**2-4*a*c) #Defining what descriminant does with disc
if disc>0:
disc1=float(disc)**0.5
return disc1 #returns and allows to be used again instead of print which doesnt allow you to use it again
else:
print("The discriminant must be greater than 0")
else: #if a is equal to 0
print ("A cannot equal 0") #Tell the user a cant equal 0
def quad_form(a, b, c): #Defining quad form w/ input a, b, c
disc2=float(descriminant(a, b, c))
quad_form1=((-1*b) + disc2/float((2*a))) #Defining + forumula for quad form
quad_form2=((-1*b) - disc2/float((2*a))) #Defining - forumula for quad form
return quad_form1, quad_form2
UI=input("Enter the coefficients of a quadratic separated by commas where A is not equal to zero: ") #User Input
a=float(UI[0])
b=float(UI[1])
c=float(UI[2])
print quad_form(a, b, c)
什麼是預期的答案,什麼是實際答案?尋求調試幫助的問題(「爲什麼這個代碼不工作?」)必須包含所需的行爲,特定的問題或錯誤以及在問題本身中重現問題所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。請參閱:[如何創建最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 – MikeJRamsey56