Python 3.x 计算角度时python中的数学域错误

Python 3.x 计算角度时python中的数学域错误,python-3.x,math,unhandled-exception,Python 3.x,Math,Unhandled Exception,试图通过给定的边来计算所有三角形的角度。 我有所有的勇气去做,一个小问题是有一个我找不到的“数学域错误”。 感谢您的帮助:) 从数学导入* def角度(a、b、c): 如果a+b您的触发器关闭。使用 从数学导入* def角度(a、b、c): 如果a+b,这个问题与三角学比编程更相关。您必须理解三角函数是如何工作的(在数学中,而不是Python中)。例如,您不能为范围之外的任何对象计算acos(c**2-a**2-b**2)/-2*a*b给出-41690.0acos取-1和1之间的值,以后请尝试自

试图通过给定的边来计算所有三角形的角度。 我有所有的勇气去做,一个小问题是有一个我找不到的“数学域错误”。 感谢您的帮助:)

从数学导入*
def角度(a、b、c):

如果a+b您的触发器关闭。使用

从数学导入*
def角度(a、b、c):

如果a+b,这个问题与三角学比编程更相关。您必须理解三角函数是如何工作的(在数学中,而不是Python中)。例如,您不能为范围之外的任何对象计算
acos
(c**2-a**2-b**2)/-2*a*b
给出
-41690.0
acos
-1
1
之间的值,以后请尝试自行调试。我花了不到一分钟的时间(我相信对于@ktzr来说也是如此)找到了有问题的行并打印了正在传递给
acos
@DeepSpace的值,下次会这样做
from math import *
def angles(a, b, c):
    if a + b <= c or a + c <= b or c + b <= a:
        return [0, 0, 0]
    elif a == b == c:
        return [60,60,60]
    tempLst = []
    d = max(a,b,c) #To know which angle is the largest
    if a == d:
        if (b ** 2 + c ** 2) < d**2: #To know wether a triangle is an obtuse triangle
           tempLst.append(round(degrees(acos((c**2 - a**2 - b**2) / (-2 * c * b)))))
           tempLst.append(round(asin(a/sin(tempLst[0])*b)))
        else:    
           tempLst.append(round(degrees(asin(c/a))))
           tempLst.append(round(degrees(asin(b/a))))
    elif b == d:
        if (a**2+c**2) < d**2:
            tempLst.append(round(degrees(acos((c**2 - a**2 - b**2)/-2*c*a))))
            tempLst.append(round(asin(b/sin(tempLst[0])*a)))
        else: 
            tempLst.append(round(degrees(asin(c/b))))
            tempLst.append(round(degrees(asin(a/b))))
    else:
        if (b**2+a**2) < d**2:
            tempLst.append(round(degrees(acos((c**2 - a**2 - b**2)/-2*a*b))))
            tempLst.append(round(asin(c/sin(tempLst[0])*b)))
        else: 
            tempLst.append(round(degrees(asin(a/c))))
            tempLst.append(round(degrees(asin(b/c))))
    tempLst.append(180 - tempLst[0] - tempLst[1])
    return tempLst
from math import *


def angles(a, b, c):
    if a + b <= c or a + c <= b or c + b <= a:
        return [0, 0, 0]
    elif a == b == c:
        return [60, 60, 60]
    tempLst = [
        round(degrees(acos((a ** 2 + b ** 2 - c ** 2) / (2 * a * b)))), # C
        round(degrees(acos((b ** 2 + c ** 2 - a ** 2) / (2 * b * c)))), # A
        round(degrees(acos((c ** 2 + a ** 2 - b ** 2) / (2 * c * a))))  # B
    ]

    return tempLst


print(angles(11, 20, 30))
# -> [149, 11, 20]