import math
i = input().split(" ")list = [int(i[0]),int(i[1]),int(i[2])]d = list[1]**2-4*list[0]*list[2] #判斷式
if d > 0 : #有兩個解ans_p = int((-1*list[1]+math.sqrt(d))/2*list[0]) #較大解 (-b + 根號(b^2 - 4*a*c))ans_n = int((-1*list[1]-math.sqrt(d))/2*list[0]) #較小解 (-b - 根號(b^2 - 4*a*c))print ("Two different roots x1=" + str(ans_p)+" , x2="+str(ans_n))elif d==0 : #重根ans = int(-1*list[1]/2*list[0]) #(-b / 2a)print ("Two same roots x=" + str(ans))else: #無解print("No real root")
2*list[0]要用括號包起來
import math
i = input().split(" ")list = [int(i[0]),int(i[1]),int(i[2])]d = list[1]**2-4*list[0]*list[2] #判斷式
if d > 0 : #有兩個解ans_p = int((-1*list[1]+math.sqrt(d))/2*list[0]) #較大解 (-b + 根號(b^2 - 4*a*c))ans_n = int((-1*list[1]-math.sqrt(d))/2*list[0]) #較小解 (-b - 根號(b^2 - 4*a*c))print ("Two different roots x1=" + str(ans_p)+" , x2="+str(ans_n))elif d==0 : #重根ans = int(-1*list[1]/2*list[0]) #(-b / 2a)print ("Two same roots x=" + str(ans))else: #無解print("No real root")2*list[0]要用括號包起來
問題已解決,感激大神!