【发布时间】:2017-02-23 06:21:17
【问题描述】:
我正在尝试使用给定坐标找到 10 点多边形的周长。
这就是我到目前为止所得到的
但是一直报错
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)
【问题讨论】:
-
看起来像一个 8 点多边形。
segments()是什么?请发布所有相关代码。还有——为什么是abs?距离已经是积极的。另外 - 你的缩进似乎是错误的。最后的print不应缩进。 -
我对 python 很陌生,我做了这些更改,但我不知道如何将列表元素定义为 poly[x,y] def perimeter(poly): """A 序列的 x 和 y (x,y) 数字坐标对 """ 返回 (sum(math.hypot(x0-x1,y0-y1) for ((x0, y0), (x1, y1)) print (perimeter(poly))
-
您遇到什么错误?什么线?仅仅说你不断收到错误是没有信息的。
segments()是什么?如果没有看到该代码,任何人都很难说什么(除了缩进问题)。 -
我在定义 poly[x,y] 时遇到错误我希望将列表中的点定义为 x 和 y,以便它们可以在等式中使用。 segements 功能现已被移除
-
如果函数
segments()已被删除,那么该代码会给您一个尝试使用该函数的错误(在您的return行中)。请向我们展示您的错误的整个追溯。
标签: python