2017-02-12 2 views
-1

삼각형의 측면에 대한 사용자 입력을 받아 직각 삼각형 인 경우 해당 영역을 인쇄하는 프로그램을 작성해야합니다. 저의 임무는 또한 어느 쪽이 다른 쪽의 합보다 길지 않은지 확인하도록 요구합니다. 나는 내 코드가 다른 두면의 합보다 길지 않고 사용자가 다시 시작하도록하지 않는면에서 어떻게 작동하는지 알아 내려고 노력했지만 손실이 발생했습니다. 나는 또한 내 프로그램이 실행될 때 none이라는 단어를 인쇄 할 때 내 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() 
+0

처럼 return 문을 사용해야합니다! 이 상태를 테스트 할 필요가 전혀 없습니다. –

답변

0

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') 

, right_tri의 구현해야 다음 (파이썬이에 의존로) 코드의 들여 쓰기가 올바른지 가정 당신이 알고 결코 때문에 여러 조건에 대한 이유는 사용자가 a 또는 b 또는 c에 대한 빗변을 표시합니다. right_tri 기능에서

0

당신은 **는 한 쪽이 다른 양측의 ** 합보다 긴 것이 불가능 어떤 삼각형 그냥

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'