delta.py

Created by teivaetienne

Created on December 19, 2024

1.13 KB


import math

def solve_quadratic(a, b, c):
    """
    Résout une équation quadratique de la forme ax^2 + bx + c = 0.
    """
    # Calcul du discriminant
    delta = b ** 2 - 4 * a * c

    # Affichage du discriminant
    print("Discriminant (Delta) =", delta)

    # Vérification des cas en fonction de Delta
    if delta > 0:
        # Deux solutions réelles distinctes
        x1 = (-b - math.sqrt(delta)) / (2 * a)
        x2 = (-b + math.sqrt(delta)) / (2 * a)
        print("Deux solutions réelles distinctes :")
        print("x1 =", x1)
        print("x2 =", x2)
    elif delta == 0:
        # Une solution réelle unique
        x1 = -b / (2 * a)
        print("Une solution réelle unique :")
        print("x =", x1)
    else:
        # Deux solutions complexes
        real_part = -b / (2 * a)
        imaginary_part = math.sqrt(-delta) / (2 * a)
        print("Deux solutions complexes :")
        print("x1 =", complex(real_part, -imaginary_part))
        print("x2 =", complex(real_part, imaginary_part))

# Exemple d'utilisation
# Coefficients de l'équation ax^2 + bx + c = 0
a = 1
b = -3
c = 2

solve_quadratic(a, b, c)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.