Discuss / Python / def quadratic(a,b,c):

def quadratic(a,b,c):

Topic source

AlexMou54

#1 Created at ... [Delete] [Delete and Lock User]
    if not isinstance(a+b+c,(int,float)):
        raise TypeError('bad operand type')    
    s=b**2-4*a*c
    if s < 0:
        return '无实数根'
    else:
        x1 = (-b+math.sqrt(s))/(2*a)
        x2 = (-b-math.sqrt(s))/(2*a)
        return x1,x2

  • 1

Reply