#25558: 問:這個錯在哪


pinray.hwong@gmail.com (Arsene)


import math

a,b,c = map(int , input().split())

d = (b**2) - (4*a*c)

if d < 0:

  print("No real root")

elif d == 0:

  print("Two same roots x=" +str(-b//2*a))

else:

  ans1 = (-b-math.sqrt(d))/(2*a)

  ans2 = (-b+math.sqrt(d))/(2*a)

  f_ans1 =round(ans1) 

  f_ans2 = round(ans2)

 

  print("Two different roots x1=" + str(f_ans2)+" , x2=" + str(f_ans1))

#25560: Re: 問:這個錯在哪


71087@stu.cchs.chc.edu.tw (~ pythOnia ChallengeR ~)


import math

a,b,c = map(int , input().split())

d = (b**2) - (4*a*c)

if d < 0:

  print("No real root")

elif d == 0:

  print("Two same roots x=" +str(-b//2*a))

else:

  ans1 = (-b-math.sqrt(d))/(2*a)

  ans2 = (-b+math.sqrt(d))/(2*a)

  f_ans1 =round(ans1) 

  f_ans2 = round(ans2)

 

  print("Two different roots x1=" + str(f_ans2)+" , x2=" + str(f_ans1))

1.題目提到保證輸出為整數。-->所以答案輸出前最好先轉換。

2.當判別式為0的時候。-->括號順序不太對

以上..希望有幫到你AC

#25600: Re: 問:這個錯在哪


pinray.hwong@gmail.com (Arsene)


import math

a,b,c = map(int , input().split())

d = (b**2) - (4*a*c)

if d < 0:

  print("No real root")

elif d == 0:

  print("Two same roots x=" +str(-b//2*a))

else:

  ans1 = (-b-math.sqrt(d))/(2*a)

  ans2 = (-b+math.sqrt(d))/(2*a)

  f_ans1 =round(ans1) 

  f_ans2 = round(ans2)

 

  print("Two different roots x1=" + str(f_ans2)+" , x2=" + str(f_ans1))

1.題目提到保證輸出為整數。-->所以答案輸出前最好先轉換。

2.當判別式為0的時候。-->括號順序不太對

以上..希望有幫到你AC

有了,謝謝。