April 13th, 2013, 08:26 PM
Imaginary numbers and square roots
So I am pretty new to Python. For my homework assignment in my beginner's class, I am attempting to take a quadratic equation and transfer the a, b, and c values (provided by the user) into the quadratic formula. However, after I've imported the math module, if there is a negative square root, it will give me an error such as
I was wondering if there is a function I can use to account for negative squareroots or imaginary numbers, as that particular example would have been 2i√11
Traceback (most recent call last):
File "<pyshell#40>", line 1, in <module>
ValueError: math domain error
Edit: I should add, I would like it to solve the quadratic formula, not just plug in the values.
April 13th, 2013, 09:03 PM
Use the cmath module
>>> import cmath
Comments on this post
[/code] are essential for python code and Makefiles!
April 13th, 2013, 09:56 PM
Interesting, I'll look into that module. Thanks.