import math
def quadratic(a,b,c):
    if not isinstance(a,(int ,float)):
        raise ("a is not a number")
    if not isinstance(b,(int,float)):
        raise ("b is not a anumber")
    if not isinstance(c,(int,float)):
        raise ("c is not a anumber")
    d = b * b - 4 * a * c
    if a==0:
        return ('a不能为0')
        if b==0:
            if c==0:
                return '方程根为全体实数'
            else:
                return '方程无实数根'
        else:
            x=(-b)/(2*a)
            return '方程只有一个实数根',x
    else:
        if d>0:
            x1=(-b+math.sqrt(d))/(2*a)
            x2=(-b-math.sqrt(d))/(2*a)
            return x1,x2
        elif d<0:
            return '方程无实根'
print(quadratic(2,3,1))

 

相关文章:

  • 2021-05-22
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2021-12-16
猜你喜欢
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
  • 2021-05-12
相关资源
相似解决方案