[Tutor] What am I missing??

Daniel Coughlin kauphlyn@speakeasy.org
Mon, 11 Jun 2001 15:04:52 -0700 (PDT)


well from the look of your interpriter session and the name error, it doesnt
look like you defined
the distance function in the the interpriter. try this:
>> import math
>> def distance(x1,y1,x2,y2):
..	dx = x2 - x1
.. 	dy = y2 - y1
..	dsquared = dx**2 + dy**2
..	result = math.sqrt(dsquared)
.. 	return result
..
>>distance(1,2,3,4)
2.8284 etc
>>


On Mon, 11 Jun 2001, DavidCraig@PIA.CA.GOV wrote:

> I am working through the python tutorial on "How to think like a Computer
> Scientist in Python".
>
> I know its simple but I can't find why this does not work.  This is the
> distance() I have written.  Below is the error message I get.
>
> # distance function
>
> def distance(x1, y1, x2, y2):
>     dx = x2 - x1
>     dy = y2 - y1
>     dsquared = dx**2 + dy**2
>     result = sqrt(dsquared)
>     return result
>
>
>
> Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>> import math
> >>> distance(1, 2, 4, 6)
> Traceback (most recent call last):
>   File "<pyshell#1>", line 1, in ?
>     distance(1, 2, 4, 6)
> NameError: name 'distance' is not defined
>
> TIA for any assistance : ))
>
> Dave
>
>
>
>
> D. H. Craig, CSM
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>