Discuss / Python / zy

微辣二毛

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

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

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

    return(x1, x2)

微辣二毛

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

import math

def quadratic(a, b, c):

    for i in(a, b, c):

        if not isinstance(i, (int, float)):

            raise TypeError('输入数据错误:应该输入整数或小数')

        else:

            pass

    if a == 0:

        return('a不能等于0')

    elif b**2 - 4*a*c < 0:

        return('无解')

    else:

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

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

        return x1, x2


  • 1

Reply