用户定义函数中的公式错误,用于查找三角形的边

时间:2017-10-27 22:23:22

标签: python

它显示UD函数的alpha部分的语法错误。enter image description here

import math

def getC(a, b, alpha):
    form_ula = (math.pow(a, 2) + math.pow(b, 2) - (2 * a * b * cos alpha)) 
    return form_ula

2 个答案:

答案 0 :(得分:2)

看起来你没有将alpha传递给cos函数(应该是cos(alpha)

此外,您只需返回第一行:

def getC(a, b, alpha):
    return math.pow(a, 2) + math.pow(b, 2) - (2 * a * b * math.cos(alpha))

答案 1 :(得分:1)

应该是math.cos(alpha)))而不是cos alpha))。它只是一个语法错误。您可以在编辑器中查看错误详细信息以识别此类错误。

import math
def getC(a, b, alpha):
    form_ula = (math.pow(a, 2) + math.pow(b, 2) - (2 * a * b * math.cos(alpha)))
    return form_ula