Hackerss.com

hackerss
hackerss

Posted on

Python Resolver la formula general ecuacion cuadratica

Resolver la formula general ecuacion cuadratica - Python:


def quadratic(a,b,c):
    """
    Resolve the quadratic equation.

    Parameters
    ----------
    a : int
        Coefficient of the quadratic equation.
    b : int
        Coefficient of the quadratic equation.
    c : int
        Coefficient of the quadratic equation.

    Returns
    -------
    tuple
        The roots of the quadratic equation.
    """

    #calculate the discriminant
    d = (b**2) - (4*a*c)

    #compute the roots
    root1 = (-b + d**0.5)/(2*a)
    root2 = (-b - d**0.5)/(2*a)

    #return the roots
    return (root1, root2)

#example
result = quadratic(1,2,1)
#output
print(result)  #(-0.5, -1.0)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)