[Tutor] What am I missing??
ak@silmarill.org
ak@silmarill.org
Mon, 11 Jun 2001 18:08:13 -0400
On Mon, Jun 11, 2001 at 02:45:55PM -0700, 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
Where did you type this in? You have two choices that would both work:
first, you can type it in a file, e.g. distfile.py, then start the
interpreter, and do this:
>>> from distfile import distance
>>> import math
>>> distance(1,2,4,6)
OR
you can type the function in the interpreter, like this:
>>> def distance(x1,y1,x2,y2):
>>> dx = x2 - x1
[...]
and then use it this time without the need to import distance.
>
>
>
> 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
--
The point of philosophy is to start with something so simple as not
to seem worth stating, and to end with something so paradoxical
that no one will believe it.