On Sat, 2 Jul 2005, Reed L. O'Brien wrote:

> >     Does anyone know how to make Python calculate square roots?
> >
> Raise to the 1/2 power.
>
> >>> 4**.5
> 2.0
> >>> 16**.5
> 4.0
> >>> 81**.5
> 9.0


By the way, if you need to take the square roots of negative numbers, then
the 'sqrt' function in the cmath module should do the trick:

######
>>> (-1)**0.5
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: negative number cannot be raised to a fractional power
>>>
>>> import cmath
>>> cmath.sqrt(-1)
1j
######


Best of wishes!

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to