#26349: [Python] 卡 NA:80%


ourclasshomework@gmail.com (Alpha)


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")
#26351: Re:[Python] 卡 NA:80%


asnewchien@gmail.com (david)


小小建議

list 是關鍵字,別拿來當變數名稱

#26361: Re:[Python] 卡 NA:80%


cges30901 (cges30901)


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]要用括號包起來

#26505: Re:[Python] 卡 NA:80%


ourclasshomework@gmail.com (Alpha)


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]要用括號包起來

問題已解決,感激大神!