a quadratic formula python treating floats as strings

You are witnessing complex numbers, not strings. When the discriminant b*b-4*a*c is negative, the solution is not real valued. The imaginary unit is denoted j in Python and complexes print like (a+bj) in Python. You may want to check if the discriminant is positive before computing, and use the math.sqrt function, which returns a float, instead of the cmath.sqrt function, which returns a complex.

Also note you called the function cubic_formula, but are calculating quadratic_formula.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top