为什么少个括号就错了
import math
def quadratic_equation(a, b, c):
t = math.sqrt(b * b - 4 * a *c)
x1 = (-b + t)/2 * a
x2 = (-b - t)/2 * a
return x1, x2
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)
x1 = (-b + t)/(2 * a)
x2 = (-b - t)/(2 * a)
return x1, x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
就对了,就是把 2 * a 改成 (2 * a),为什么呢,运算的顺序不是一样的吗