42 lines
866 B
Python
42 lines
866 B
Python
# Import de la racine carrée
|
|
from math import sqrt
|
|
|
|
# Saisir a
|
|
a = int(input("a?"))
|
|
# Saisir b
|
|
b = int(input("b?"))
|
|
# Saisir c
|
|
c = int(input("c?"))
|
|
|
|
# On calcul le discriminant
|
|
# delta prend la valeur b^2 - 4ac
|
|
delta = b**2 - 4*a*c
|
|
|
|
# On différencie 3 cas
|
|
# Si le discriminant est positif
|
|
if delta > 0:
|
|
# On affiche "2 solution:"
|
|
print("2 solutions:")
|
|
# On calcul x1
|
|
x1 = (-b - sqrt(delta))/(2*a)
|
|
# On calcul x2
|
|
x2 = (-b + sqrt(delta))/(2*a)
|
|
# On affiche x1
|
|
print("x1 = ", x1)
|
|
# On affiche x1
|
|
print("x2 = ", x2)
|
|
|
|
# Si le discriminant est nul
|
|
elif delta == 0:
|
|
# On affiche "Une solution: "
|
|
print("Une solution:")
|
|
# On calcule x1
|
|
x1 = -b / (2*a)
|
|
# On affiche x1
|
|
print("x1 = ", x1)
|
|
|
|
# Dernier cas, le discriminant est alors négatif
|
|
else:
|
|
# On affiche "Pas de solution"
|
|
print("Pas de solution")
|