#26349: [Python] 卡 NA:80%


ourclasshomework@gmail.com (Alpha)

學校 : 不指定學校
編號 : 158666
來源 : [114.36.3.19]
最後登入時間 :
2023-10-16 13:05:12
a006. 一元二次方程式 | From: [114.32.54.88] | 發表日期 : 2021-08-03 00:22

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)

學校 : 不指定學校
編號 : 68108
來源 : [1.168.27.116]
最後登入時間 :
2024-03-31 17:58:15
a006. 一元二次方程式 | From: [111.246.62.234] | 發表日期 : 2021-08-03 01:48

小小建議

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

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


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
a006. 一元二次方程式 | From: [39.10.131.149] | 發表日期 : 2021-08-03 15:27

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)

學校 : 不指定學校
編號 : 158666
來源 : [114.36.3.19]
最後登入時間 :
2023-10-16 13:05:12
a006. 一元二次方程式 | From: [114.32.54.88] | 發表日期 : 2021-08-10 16:04

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

問題已解決,感激大神!

 
ZeroJudge Forum