Discuss / Python / 答案

答案

Topic source

lmtooT_T

#1 Created at ... [Delete] [Delete and Lock User]
    if not isinstance(a, (int, float)):
        raise TypeError('a is not a number')
    if not isinstance(b, (int, float)):
        raise TypeError('b is not a number')
    if not isinstance(c, (int, float)):
        raise TypeError('c is not a number')
    if a == 0:
        raise TypeError('a must not be zero')
    x1 = (-b + math.sqrt(b * b - 4 * a * c)) / (2 * a)
    x2 = (-b - math.sqrt(b * b - 4 * a * c)) / (2 * a)
    return x1, x2

  • 1

Reply