Write a quadratic solver that never gives up, and a function for square roots of complex numbers. Use math.sqrt only, so you see where the comes from.
The idea. When , the roots are . In Python, complex(p, q) is the number .
Your tasks.
discriminant, return .roots, return both roots: real numbers when is not negative, and complex numbers when it is. Put the root with the plus sign first.square_root, return the square root of whose real part is not negative.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…
With Standard, you also open 11 more problems, 2 Python labs and 1 extra course. Everything you have used here stays free, always.