[Código] Ecuaciones de 2º grado

Iniciado por Mavis, Mayo 04, 2014, 12:45:37 AM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Mayo 04, 2014, 12:45:37 AM Ultima modificación: Mayo 05, 2014, 12:44:33 PM por LucaSthefano
Código: python
#!/usr/bin/env python
from math import sqrt

def Calculo(X,Y,Z):

    try:
        N1 = (-Y + ((sqrt((Y*Y) - (4*X*Z)))/(2*X)))
        N2 = (-Y - ((sqrt((Y*Y) - (4*X*Z)))/(2*X)))

return "(+) = " + str(N1) + "(-) = " + str(N2)

    except:
        return 'Sin solucion, intenta nuevamente'         

while True:
print "Ecuacion:"
X = input(' X = ')
Y = input(' Y = ')
Z = input(' Z = ')
print Calculo(X,Y,Z)


Luego de años sin practicar, no viene mal retomar las mañas...

Saludos!

Muy bueno brother, sólo un par de  observaciones:

1) Como estás importando con from math import sqrt no accedes a la función con math.sqrt() sino que lo haces sólo con sqrt().
2) Si evaluas el discriminante te puedes ahorrar el try:

Saludos!







You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Muy bueno!!! Espero nuevos aportes!!
No intentes pararme, trata de defenderte, trata de matarme, pero de cualqueir forma TE SUPERARE