assert 4**0.5 == 2

More generally: nth root of x: x ** (1.0/n)

Or even more generally, take the 3rd root of the square of x:

x ** (2.0/3.0)

And when we are already extending the scope of the mailing list to math
basics:

1.0/(x**2) == x**-2

(negating the power gives the inverse.)

Andreas


Am Donnerstag, den 13.03.2008, 18:02 -0700 schrieb Robert Childers:
> I am in an early lesson in "A Byte of Python."  Instead of writing a
> program to find the area of a rectangle I thought it would be useful
> to write a program to determine the length of the diagonal of a
> "golden rectangle", which would of course equal the sq root of the sum
> of the squares of the width and height.  Here is my program:
> >>> height = input ("Height:")
> Height:1
> >>> width = input ("Width:")
> Width:1.618
> >>> int = ((height**2) + (width**2))
> >>> print int
> 3.617924
> >>> hypotenuse * hypotenuse = int
> SyntaxError: can't assign to operator
>  
> I looked ahead in the lesson and could find no mention of square
> roots.  How do I find the square root of an integer?
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to