無法理解-6怎么來的
import math
def quadratic_equation(a, b, c):
? ? if b**2 - 4*a*c >= 0:
? ? ? ? x1 = (-b + math.sqrt(b**2 - 4*a*c))/2*a
? ? ? ? x2 = (-b - math.sqrt(b**2 - 4*a*c))/2*a
? ? return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2018-08-07
大柚子,你把2*a變成(2*a)就好了,運算順序。。)逃
2018-08-25
這里涉及到運算符的優先級
2018-08-07
x1 = (-b + math.sqrt(b**2 - 4*a*c))/(2*a)
x2 = (-b - math.sqrt(b**2 - 4*a*c))/(2*a)
2018-08-07
? x1 = (-b + math.sqrt(b**2 - 4*a*c))/2*a
? ? ? ? x2 = (-b - math.sqrt(b**2 - 4*a*c))/2*a
對應: ax^2 +bx+c=0