def roots4(a,b,c,d):
d = b * b - 4 * a * c
if a != 0 and d == 0:
roots4(a,b,c,d)
x = -b/ (2*a)
if a != 0 and d > 0:
roots4(a,b,c,d)
x1 = (-b + math.sqrt(d)) / 2.0 / a
x2 = (-b - math.sqrt(d)) / 2.0 / a
if a != 0 and d < 0:
roots4(a,b,c,d)
xre = (-b) / (2*a)
xim = (math.sqrt(d))/ (2*a)
print x1 = xre + ixim
strx1 = "x2 = %6.2f + i %6.2f" %(xre, xim)
print strx1
This is part of my code for a project. What im trying to do is define "roots4(a,b,c,d)". For example, in the case that "a != 0 and d == 0" then roots4(a,b,c,d) shall then go to to finding x by solving equation "x = -b/ (2*a)". And so on... i dont know what im doing wrong. Any tips?
Aucun commentaire:
Enregistrer un commentaire