-1
這是我的代碼來計算兩邊和一個角度時,三角形的第三邊。角度的輸入應該是度,但自math.cos()以弧度爲單位的值,所以我們需要將其轉換。蟒蛇數學域誤差計算三角形的第三角度
import math
a = float(input("enter value for side 1:"))
b = float(input("enter value for side 2:"))
c = float(input("enter angle value in degrees:"))
e = math.radians(c)
g = (a * a) + (b * b)
d = math.sqrt(g - (2 * a * c * (math.cos(e))))
print("third side value", d)
我收到以下錯誤:
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/untitled/question3.py", line 7, in <module>
d = math.sqrt(g - (2 * a * c * (math.cos(e))))
ValueError: math domain error
任何整改?