[Tutor] Value Error

Dave Angel davea at davea.name
Thu Jun 13 00:31:47 CEST 2013


On 06/12/2013 06:07 PM, Jim Mooney wrote:
> On 12 June 2013 14:16, Steve Willoughby <steve at alchemy.com> wrote:
>
>> or if you try to take the square root of a negative number, etc.
>>
>
> Or the log of -10. Although sqrt(-1) works fine for cmath.sqrt(-1) - I
> think I get it.
>
> Come to think of it you can do cmath.log(-10), but that's getting scary ;')
>
> Jim
>
 >>> import math, cmath
 >>> i = complex(0,1)
 >>> math.sqrt((math.e **(i * math.pi)).real)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ValueError: math domain error

 >>> cmath.sqrt(float((math.e **(i * math.pi)).real))
1j



-- 
DaveA


More information about the Tutor mailing list