Discuss / Python / 练习作业

练习作业

Topic source

我更好呀

#1 Created at ... [Delete] [Delete and Lock User]

def quadratic(a, b, c):

    if not (isinstance(a, (int, float)) and isinstance(b, (int, float)) and isinstance(c, (int, float))): #数据类型检查

        raise TypeError('bad operand type')

    else:

        delta = b**2 - 4*a*c

    if delta < 0:

        return

    elif delta == 0:

        x1 = x2 = -b/(2*a)

        return x1

    else:

        x1 = (-b + math.sqrt(delta))/(2*a)

        x2 = (-b - math.sqrt(delta))/(2*a)

        return x1,x2


  • 1

Reply