2014-2015/1S/Analyse/Facto2ndDeg/Cours/sol_deg2.py

42 lines
866 B
Python
Raw Permalink Normal View History

2017-06-16 06:48:07 +00:00
# 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")