我是否需要单独对a变量进行判定是否为0?
import math
def quadratic_equation(a, b, c):
if a == 0:
x1 = b/(-c)
return x1
else:
'''
t = math.sqrt(b*b-4*a*c)
x1 = (-b + t) / (2 * a)
x2 = (-b - t) / (2 * a)
return x1,x2
'''
x1 = ((-b)+math.sqrt(b*b-4*a*c))/(2*a)
x2 = ((-b)-math.sqrt(b*b-4*a*c))/(2*a)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
print quadratic_equation(0,2,1)
而且最后如果a= 0得出的结果就是一个-2,不是tuple,是怎么回事?