求助求助,個人感覺程序沒有錯誤,為什么運行出錯,用的notepad++
import math
def quadratic_equation(a, b, c):
? ? y = b*b - 4*a*c
? ? if y < 0:
? ? ? ? return?
? ? else:
? ? ? ? x1 = (-b+math.sqr(y))/(2*a)
? ? ? ? x2 = (-b-math.sqr(y))/(2*a)
? ? ? ? return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
cmd顯示如下:
F:\PythonTest>python test.py
Traceback (most recent call last):
? File "test.py", line 12, in <module>
? ? print quadratic_equation(2,3,0)
? File "test.py", line 9, in quadratic_equation
? ? x1 = (-b+math.sqr(y))/(2*a)
AttributeError: 'module' object has no attribute 'sqr'
2016-12-05
數學函數用錯了,開方是math.sqrt()