定义求解一元二次方程的根的函数哪里错了,运行后一直提示定义函数语法错误
import math
def quadratic(a,b,c)
if not isinstance(a,b,c,(int,float)):
raise TypeError('bad operand type')
d = b**2-4*a*c
if d > 0:
x1 = (-b+math.sqrt(d))/(2*a)
x2 = (b+math.sqrt(d))/(2*a)
elif d = 0:
x1 = -b/(2*a)
x2 = x1
else
return False
x1,x2 = quadratic(2,3,1)
print(x1,x2)
修改如下,供参考:
import math
def quadratic(a,b,c):
if isinstance((a,b,c),(int,int,int)):
raise TypeError('bad operand type')
d = b**2-4*a*c
if d > 0:
x1 = (-b+math.sqrt(d))/(2*a)
x2 = (b+math.sqrt(d))/(2*a)
elif d == 0:
x1 = -b/(2*a)
x2 = x1
else:
return False
return x1, x2
x1,x2 = quadratic(2,3,1)
print(x1,x2)