[Tutor] hypotenuse
bob gailer
bgailer at alum.rpi.edu
Fri Mar 14 19:20:21 CET 2008
Robert Childers wrote:
> I have rewritten my "hypotenuse" program as follows:>>> #This program
> calculates the width and diagonal of a golden rectangle
> >>> print "Calculate the width and diagonal of a golden rectangle."
> Calculate the width and diagonal of a golden rectangle.
> >>> height = input ("Input height:")
> Input height:1
> >>> width = height*1.618
> >>> print "Width:", width
> Width: 1.618
> >>> import math
> >>> hyp_squared = height**2 + width**2
> >>> hypotenuse = math.sqrt(hyp_squared)
> >>> print "Diagonal:", hypotenuse
> Diagonal: 1.90208412012
>
> When I save the program then try to run the module I get an error
> message that it is invalid.
Please ALWAYS post the code and the traceback. Otherwise we have no way
to easily help you.
But I will take a guess that you saved the contents of the interactive
session and tried to run that. That will not work, as the interactive
session is full of >>> and results of print statements.
So I suggest you edit the module to see if this is the case; if it is
then remove all the junk so you just have pure Python. Run that. If you
still get errors post the code and traceback.
--
Bob Gailer
919-636-4239 Chapel Hill, NC
More information about the Tutor
mailing list