是什么导致了这个问题?python数学域错误 - sqrt
from math import sqrt
print "a : "
a = float(raw_input())
print "b : "
b = float(raw_input())
print "c : "
c = float(raw_input())
d = (a + b + c)/2
s = sqrt(d*(d-a)*(d-b)*(d-c))
print "a+b+c =", a, b, c
print "Distr. =", d*2, "Area =", s
错误:
Traceback (most recent call last):
File "C:/Python27/fájlok/háromszög terület2.py", line 11, in <module>
s = sqrt(d*(d-a)*(d-b)*(d-c))
ValueError: math domain error
检查是否总d *(DA)*(DB)的*(dc)是正数,因为sqrt(-1)是数学中的复数,但不是python – CY5 2015-03-31 18:39:06
而且通常我们会问,当您发布“为什么会出现此错误?”时,还会包含导致该错误的输入。 – Teepeemm 2015-04-01 01:52:57