是什麼導致了這個問題?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