#26381: 想請問這樣錯在哪(python)

#### ne7ck31690@gmail.com (阿胡)

School : No School
ID : 159924
2021-08-04 12:11:18
a006. 一元二次方程式 | From: [123.110.38.177] | Post Date : 2021-08-04 05:42

a,b,c=map(int,input().split())
d = b**2 - 4*a*c
if d < 0:
print('No real root')
elif d ==0:
r = int(-b/2*a)
print('Two same roots x={}'.format(r))
else:
n = int(d ** 0.5)
r1 = int((-b + n ) / (2*a))
r2 = int((-b - n ) / (2*a))
if r1 < r2 :
r1,r2 = r2,r1
print('Two different roots x1={} , x2={}'.format(r1,r2))

您的答案為: Two same roots x=-4

#26382: Re:想請問這樣錯在哪(python)

#### cges30901 (cges30901)

School : No School
ID : 30877
2021-09-21 21:45:15
a006. 一元二次方程式 | From: [39.10.131.149] | Post Date : 2021-08-04 07:55

a,b,c=map(int,input().split())
d = b**2 - 4*a*c
if d < 0:
print('No real root')
elif d ==0:
r = int(-b/2*a)
print('Two same roots x={}'.format(r))
else:
n = int(d ** 0.5)
r1 = int((-b + n ) / (2*a))
r2 = int((-b - n ) / (2*a))
if r1 < r2 :
r1,r2 = r2,r1
print('Two different roots x1={} , x2={}'.format(r1,r2))

您的答案為: Two same roots x=-4

2*a要用括號包起來

ZeroJudge Forum