[Tutor] hypotenuse

Andreas Kostyrka andreas at kostyrka.org
Fri Mar 14 02:27:12 CET 2008


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 at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20080314/495e56c5/attachment.pgp 


More information about the Tutor mailing list