Why do I get ValueError : math domain error?
<p>I wrote a function named <code>analyze_the_shape</code> that takes a list of 2D vertices such that the list is in the order of a clockwise traversal of the vertices in the 2D Euclidean space.</p>

<p>I call it in the interpreter and give <code>[(0, 0), (0, 4.0), (4.0, 4.0), (4.0, 0)]</code> as input but I get <code>ValueError : math domain error</code>. I expect to see <code>return ["SQUARE", 4.0]</code>. What can I do ?       </p>

<pre><code>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] - liste[2][0])**2 + (liste[3][1] - liste[2][1])**2 )**(0.5))
        d4 = abs(( (liste[0][0] - liste[3][0])**2 + (liste[0][1] - liste[3][1])**2 )**(0.5)) 
        hypo = abs(( (liste[2][1] - liste[0][1])**2 + (liste[2][0] - liste[0][0])**2 )**(0.5))
        cos_angle = float((hypo**2 - (d3)**2 + (d4)**2) / ((-2.0)*(d4)*(d3)))
        angle = math.degrees(math.acos(cos_angle))
        if d1 == d2 == d3 == d4 and abs(angle - 90.0) &lt; 0.001 :
            return ["SQUARE", d1]  
</code></pre>

<p>This is the error I get:</p>

<pre><code>&gt;&gt;&gt; import a
&gt;&gt;&gt; a.analyze_the_shape([(0, 0), (0, 4.0), (4.0, 4.0), (4.0, 0)])
Traceback (most recent call last):
File "&lt;stdin&gt;", line 1, in &lt;module&gt;
File "a.py", line 15, in analyze_the_shape

ValueError: math domain error
</code></pre>
