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