函数返回值
import math def quadratic_equation(a, b, c): t=(b*b)-(4*a*c) x=math.sqrt(t) if x>=0: return (-b+x)/(2*a),(-b-x)/(2*a) else: return none print quadratic_equation(2, 3, 0) print quadratic_equation(1, -6, 5) 天啦!怎么错的啊
import math def quadratic_equation(a, b, c): t=(b*b)-(4*a*c) x=math.sqrt(t) if x>=0: return (-b+x)/(2*a),(-b-x)/(2*a) else: return none print quadratic_equation(2, 3, 0) print quadratic_equation(1, -6, 5) 天啦!怎么错的啊
2017-02-20
import math def quadratic_equation(a, b, c): l=b**2-4*a*c x=math.sqrt(l) if x>=0: return (-b+x)/(2*a), (-b-x)/(2*a) else: return nothing quadratic_equation(2, 3, 0) print quadratic_equation(1, -6, 5)
为啥我的输出来的不是正确答案。。。。啊
>>> import math
>>> def quadratic_equation(a, b, c):
... l=b**2-4*a*c
... x=math.sqrt(l)
... if x>=0:
... return (-b+x)/(2*a), (-b-x)/(2*a)
... else:
... return nothing
...
>>> quadratic_equation(2, 3, 0)
(0.0, -1.5)
>>> print quadratic_equation(1, -6, 5)
(5.0, 1.0)
>>>
举报