ValueError: math domain error, keeps popping up
<p>I keep getting this message from time to time.
i tried all variations, changing the way i use the sqrt, doing it step by step..etc 
But still this error keeps popping up.
It might be a rookie mistake which i am not noticing since i am new to python and ubuntu.
This is my source code:-(a very simple program)</p>

<pre><code>#To find the area of a triangle
a=input("Input the side 'a' of a triangle ")
b=input("Input the side 'b' of a trianlge ")
c=input("Input the side 'c' of a triangle ")
from math import *
s=(a+b+c)/2
sq=(s*(s-a)*(s-b)*(s-c))
area=(sqrt(sq)) 
perimeter=2*(a+b)
print "Area = ", area
print "perimeter=", perimeter
</code></pre>

<p>and this is the error i keep getting </p>

<pre><code>Traceback (most recent call last):

   line 8, in &lt;module&gt;

    area=(sqrt(sq))

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

<p>If a,b,c doesn't form a triangle, sq will come out to be -ve.
Check if <code>s*(s-a)*(s-b)*(s-c)</code> is positive because sqrt(-ve number)  is a complex number. </p>

<p>To resolve this issue, you can use exception handling. </p>

<pre><code>try:
  a=input("Input the side 'a' of a triangle ")
  b=input("Input the side 'b' of a trianlge ")
  c=input("Input the side 'c' of a triangle ")
  from math import *
  s=(a+b+c)/2
  sq=(s*(s-a)*(s-b)*(s-c))
  area=(sqrt(sq)) 
  perimeter=2*(a+b)
  print "Area = ", area
  print "perimeter=", perimeter
except ValueError:
  print "Invalid sides of a triangle"
</code></pre>

python math