Created
January 31, 2018 12:57
-
-
Save israelem/b27720dbf4b4988b2f1cbbda5c6db0ab to your computer and use it in GitHub Desktop.
Código para resolver ecuaciones de segundo grado. Solo devuelve soluciones reales
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
print('Programa para calcular las soluciones de una ecuación de segundo grado') | |
respuesta = 'S' | |
while respuesta == 'S': | |
a = float(input('Valor de a: ')) | |
b = float(input('Valor de b: ')) | |
c = float(input('Valor de c: ')) | |
if a == 0: | |
print('No es una ecuación de segundo grado') | |
else: | |
discriminante = b**2 - 4*a*c | |
if discriminante < 0: | |
print('No hay soluciones reales') | |
else: | |
x1 = (-b + sqrt(discriminante)) / (2 * a) | |
x2 = (-b - sqrt(discriminante)) / (2 * a) | |
if x1 == x2: | |
print('Solución: x1 =', round(x1, 2)) | |
else: | |
print('Soluciones: x1 =', round(x1, 2), 'y x2 =', round(x2, 2)) | |
respuesta = input('¿Quieres resolver otra ecuación? [S/N] ') | |
while respuesta not in 'SN': | |
respuesta = input('¿Quieres resolver otra ecuación? [S/N] ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ty