如果公式判断小于0,我们应该返回什么呢?
import math
def quadratic_equation(a, b, c):
t=math.sqrt(b*b-4*a*c)
if t>=0:
return (-b+t)/(2*a),(-b-t)/(2*a)
else:
return 0
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
import math
def quadratic_equation(a, b, c):
t=math.sqrt(b*b-4*a*c)
if t>=0:
return (-b+t)/(2*a),(-b-t)/(2*a)
else:
return 0
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2016-03-14
举报