View previous topic :: View next topic |
Author |
Message |
li1_getoo l33t
Joined: 20 Oct 2002 Posts: 661 Location: Queens , NY
|
Posted: Sun Jan 12, 2003 3:36 am Post subject: noob question for Python |
|
|
Code: | #!/usr/bin/python
import math
def FindClosestPointAboveXAxis(PointList,TargetPoint):
"""Given a list of points and a target point,this function
returns
the list's closest point, and its distance from the
target. It ignores all points with a negative y-coordinate. We
represent points in the plane (or on screen) as a two-valued
tuple of the form (x-coordinate,y-coordinate).***
ClosestPoint=None
for Point in PointList:
if (Point[1]<0):
continue
DistPoint=math.sqrt((TargerPoint[0]-Point[0])**2 +
(TargetPoint[1]-Point[1])**2)
if (ClosestDistance == None or
DistPoint < ClosestDistance):
ClosestPoint=Point
ClosestDistance = DistanceToPoint
if (DistanceToPoint==0):
print "Point found in the list"
break
else:
print "Point not found on the list"
return (ClosestPoint, ClosestDistance) |
this is what i get when running it in a terminal
Code: | bash-2.05b$ ./ClosestPoint.py
File "./ClosestPoint.py", line 28
^
SyntaxError: invalid token
|
thanx
i know its an easy question , and i feel retarded but , i want to learn ... this is a script from Python 2.1 bible ClosestPoint.py |
|
Back to top |
|
|
BigRedDot n00b
Joined: 29 Oct 2002 Posts: 67 Location: Austin
|
Posted: Sun Jan 12, 2003 5:52 am Post subject: |
|
|
Code: | tuple of the form (x-coordinate,y-coordinate).*** |
Try closing the comment with triple quotes instead of triple asterisks. _________________ Even if you are one-in-a-million, there are still 6000 people just like you. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|