+ 2
Why doesn't this work?
So I am trying to create a second grade equation solver and, at the step where I have to do the root of b^2-4ac, an error about math domain appears https://code.sololearn.com/ctoH936dFX8S/?ref=app
2 ответов
+ 2
you get this error because of negative values you are passing to the math.sqrt function.
instead of math, use cmath library, and it's sqrt function. it will solve your problem, and give complex number for negative numbers .
import cmath
cmath.sqrt(argument)
or just import only sqrt fn as
from cmath import sqrt
#and then use
sqrt(agrument)
+ 3
Thank you very much!