perimeter of a polygon with given coordinates
<p>i am trying to find the perimeter of  10 point polygon with given coordinates. </p>

<p>This is what ive got so far</p>

<p>however keep getting an error</p>

<pre><code>poly = [[31,52],[33,56],[39,53],[41,53],[42,53],[43,52],[44,51],[45,51]]
x=row[0]
y=row[1]

``def perimeter(poly):
    """A sequence of (x,y) numeric coordinates pairs """
    return abs(sum(math.hypot(x0-x1,y0-y1) for ((x0, y0), (x1, y1)) in segments(poly)))

    print perimeter(poly)
</code></pre>

<p><code>poly</code> is a list, to index an element in this list, you need to supply a single index, not a pair of indices, which is why <code>poly[x,y]</code> is a syntax error. The elements are lists of length 2. If <code>p</code> is one of those elements, then for that point <code>(x,y) = (p[0],p[1])</code>. The following might give you an idea. <code>enumerate</code> allows you to simultaneously loop through the indices (needed to get the next point in the polygon) and the points:</p>

<pre><code>&gt;&gt;&gt; for i,p in enumerate(poly):
    print( str(i) + ": " + str((p[0],p[1])))


0: (31, 52)
1: (33, 56)
2: (39, 53)
3: (41, 53)
4: (42, 53)
5: (43, 52)
6: (44, 51)
7: (45, 51)
</code></pre>

python