Question: Using Python! Exercise 3.8: Write a function for solving ax2 + bx + c = 0 a) Given a quadratic equation ax? + bx +
Using Python!
Exercise 3.8: Write a function for solving ax2 + bx + c = 0 a) Given a quadratic equation ax? + bx + c = 0, write a function roots(a, b, c) that returns the two roots of the equation. The returned roots should be float-type objects when the roots are real, otherwise complex-type objects. Hint You can test on the sign of the expression in the square root and return stan- dard float or complex Python objects accordingly. Alternatively, you can simply use sqrt from the numpy.lib.scimath library, see Chap. 1.6.3. This sqrt func- tion returns an object of type numpy.complex128 in case of a negative argument (and hence a complex square root) and an object of type numpy.float64 other- wise
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
