Function 三角不等式

Function 三角不等式,function,python-3.x,return-value,Function,Python 3.x,Return Value,我必须编写一个程序,接受用户对三角形边的输入,并打印出它是否是直角三角形以及面积是多少。我的作业还要求我们确保没有一条边比其他两条边的总和长。我曾试图找出如何让我的代码在一个不长于其他两个方面的总和的方面工作,并提示用户重新开始,但我不知所措。我还遇到了一个问题,当我的程序运行时,它会打印“无”,我认为这与我的def right_tri功能有关,但我不确定它为什么会这样做 这是我的代码,任何帮助都将不胜感激 def area(a, b, c): s = (a + b + c) / 2

我必须编写一个程序,接受用户对三角形边的输入,并打印出它是否是直角三角形以及面积是多少。我的作业还要求我们确保没有一条边比其他两条边的总和长。我曾试图找出如何让我的代码在一个不长于其他两个方面的总和的方面工作,并提示用户重新开始,但我不知所措。我还遇到了一个问题,当我的程序运行时,它会打印“无”,我认为这与我的def right_tri功能有关,但我不确定它为什么会这样做

这是我的代码,任何帮助都将不胜感激

def area(a, b, c):
    s = (a + b + c) / 2

   area = (s*(s-a)*(s-b)*(s-c)) **0.5
   return format(area, '.2f')

def right_tri(a, b, c):
    if (b**2 + c**2 == a**2):
       print('Is a right triangle')

else:
      print('Is not a right triangle')

def main () :

    a = int(input('Enter longest side of the triangle'))
    b = int(input('Enter the second side of the triangle'))
    c = int(input('Enter the thrid side of the triangle'))

    print('Area is:', triangle.area(a, b, c))
    print(triangle.right_tri(a, b, c))
    print(is_sum(a, b, c))

 def is_sum(a, b, c):
     if (a > b + c) or (b > a + c) or (c > a + b):
        print ('One side is longer than the sum of the other two sides')
 else:
     return True

main ()  

假设代码的缩进是正确的(因为python依赖它),下面应该是
right\u tri
的实现

def right_tri(a, b, c):
    if ((b**2 + c**2 == a**2) || (a**2 + c**2 == b**2) || (b**2 + a**2 == c**2)):
       print('Is a right triangle')

    else:
      print('Is not a right triangle')

出现多个条件的原因是,您永远不知道用户是否为
a
b
c
提供斜边,在right\u tri函数中,您需要使用return语句,就像

    def right_tri(a, b, c):
        if (b**2 + c**2 == a**2):
            return 'Is a right triangle'
        else:
            return 'Is not a right triangle'
对于任何三角形,不可能一条边比另两条边的和长!绝对没有必要测试这种情况。