def quadratic(a, b, c):
if not isinstance(a,(int, float)):#先进行参数类型检查
raise TypeError('the bad operand type of a')
elif not isinstance(b,(int, float)):
raise TypeError('the bad operand type of b')
elif not isinstance(c,(int, float)):
raise TypeError('the bad operand type of c')
elif (b**2) - (4*a*c) < 0:
return "此方程无解"
else:
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
Sign in to make a reply
丶我好烦丶
def quadratic(a, b, c):
if not isinstance(a,(int, float)):#先进行参数类型检查
raise TypeError('the bad operand type of a')
elif not isinstance(b,(int, float)):
raise TypeError('the bad operand type of b')
elif not isinstance(c,(int, float)):
raise TypeError('the bad operand type of c')
elif (b**2) - (4*a*c) < 0:
return "此方程无解"
else:
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