一元二次方程:ax² + bx + c = 0
求根公式:x = (-b+√(b²-4ac))/2a
判别式:b²-4ac
def my_math(a, b , c):
if not isinstance(a,(int, float)) and not isinstance(b, (int, float)) and not isinstance(c, (int, float)) :
raise TypeError("输入的参数类型有误" + a)
# elif not isinstance(b, (int, float)):
# raise TypeError("输入的参数类型有误" + b)
# elif not isinstance(c, (int, float)):
# raise TypeError("输入的参数类型有误" + c)
else:
dist = pow(b,2) - (4 * a * c)
print(dist)
if dist == 0:
result = -b / (2 * a)
print("只有一个相同的实数:", result)
if dist < 0:
print("没有实数")
if dist > 0:
result1 = (-b + math.sqrt(dist)) /2 * a
result2 = (-b - math.sqrt(dist)) / 2 * a
print(result1)
print(result2)
my_math(-6,6,6)