小编Ali*_*dan的帖子

为什么我会得到ValueError:math域错误?

我写了一个名为的函数analyze_the_shape,它接受一个2D顶点列表,使得列表按照2D欧几里德空间中顶点的顺时针遍历顺序排列.

我在解释器中调用它并给出[(0, 0), (0, 4.0), (4.0, 4.0), (4.0, 0)]输入但是我得到了ValueError : math domain error.我希望看到return ["SQUARE", 4.0].我能做什么 ?

import math

def analyze_the_shape(liste):
    if len(liste) == 2 :
        d = ( (liste[1][0] - liste[0][0])**2 + (liste[1][1] - liste[0][1])**2 )**(0.5)   
        return ["LINESEGMENT", d ] 
    if len(liste) == 4 :
        d1 = abs(( (liste[1][0] - liste[0][0])**2 + (liste[1][1] - liste[0][1])**2 )**(0.5))
        d2 = abs(( (liste[2][0] - liste[1][0])**2 + (liste[2][1] - liste[1][1])**2 )**(0.5))
        d3 = abs(( (liste[3][0] - …
Run Code Online (Sandbox Code Playgroud)

python

6
推荐指数
2
解决办法
4万
查看次数

标签 统计

python ×1