<div>I have rewritten my "hypotenuse" program as follows:>>> #This program calculates the width and diagonal of a golden rectangle<br>>>> print "Calculate the width and diagonal of a golden rectangle."<br>
Calculate the width and diagonal of a golden rectangle.<br>>>> height = input ("Input height:")<br>Input height:1<br>>>> width = height*1.618<br>>>> print "Width:", width<br>
Width: 1.618<br>>>> import math<br>>>> hyp_squared = height**2 + width**2<br>>>> hypotenuse = math.sqrt(hyp_squared)<br>>>> print "Diagonal:", hypotenuse<br>Diagonal: 1.90208412012</div>
<div> </div>
<div>When I save the program then try to run the module I get an error message that it is invalid.</div>
<div>I have been assuming that if no "invalid syntax" error occurs in the shell the program should run. Could this problem be associated with the import math instruction?<br><br></div>
<div class="gmail_quote">On Fri, Mar 14, 2008 at 6:03 AM, Alan Gauld <<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">"Wolfram Kraus" <<a href="mailto:wolfram.kraus@fen-net.de">wolfram.kraus@fen-net.de</a>> wrote in message<br>
news:frdiev$m4u$1@ger.gmane.org...<br>
<div class="Ih2E3d">> Am 14.03.2008 09:40, Alan Gauld schrieb:<br>>>>> Why can you not use something like:<br>>>>><br>>>>>>>> hypotenuse = hyp_squared**1/2<br>>><br>>> And for completeness that could also be written:<br>
>><br>>> hypotenuse = pow(hyp_squared,1/2)<br>>><br>>> Again, without the need to import math.<br>>><br>> But beware of the integer divison in Python:<br>><br>> >>> pow(2,1/2)<br>
> 1<br><br></div>Good catch. Applies to the ** style too.<br><br>Alan G<br>
<div>
<div></div>
<div class="Wj3C7c"><br><br>_______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</div></div></blockquote></div><br>