求解這樣為什么不能過
import math
def quadratic_equation(a, b, c):
? ? if a == 0:
? ? ? ? return -(c/b)
? ? else:
? ? ? ? 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)
返回了(0.0, -6.0)
(5.0, 1.0)
2015-08-24
因為錯了,所以不能通過。
x1=(-b + math.sqrt( b * b - 4 * a * c ))/ 2 * a
?x2=(-b - math.sqrt( b * b - 4 * a * c ))/ 2 * a
一元二次方程是,除2a不是,除2乘a。所以2*a加一個括號就對哦。
2015-08-24
你把2*a括起來就可以了