while True:
try:
a, b, c = map(int, input().split(' '))
except:
break;
D = (b * b) - 4 * a * c
if D > 0:
x1 = (-b + (b * b - 4 * a * c) ** 0.5) / (2 * a)
x2 = (-b - (b * b - 4 * a * c) ** 0.5) / (2 * a)
print('Two different roots x1=%d , x2=%d' % (x1, x2))
elif D == 0:
x1 = -b / 2 * a
print('Two same roots x=%d' % x1)
elif D < 0:
print('No real root')
while True:
try:
a, b, c = map(int, input().split(' '))
except:
break;
D = (b * b) - 4 * a * c
if D > 0:
x1 = (-b + (b * b - 4 * a * c) ** 0.5) / (2 * a)
x2 = (-b - (b * b - 4 * a * c) ** 0.5) / (2 * a)
print('Two different roots x1=%d , x2=%d' % (x1, x2))
elif D == 0:
x1 = -b / 2 * a
print('Two same roots x=%d' % x1)
elif D < 0:
print('No real root')
請修改 x1 = -b / 2 * a 為 x1 = -b / (2 * a)