Showing posts with label Take 3 sides of a triangle as an input and find whether that triangle is a right angled triangle or not. Print 'YES' if a triangle is right angled triangle or 'NO' if it's not.. Show all posts
Showing posts with label Take 3 sides of a triangle as an input and find whether that triangle is a right angled triangle or not. Print 'YES' if a triangle is right angled triangle or 'NO' if it's not.. Show all posts
Saturday, April 1, 2023

Take 3 sides of a triangle as an input and find whether that triangle is a right angled triangle or not. Print 'YES' if a triangle is right angled triangle or 'NO' if it's not.

 


Take 3 sides of a triangle as an input and find whether that triangle is a right angled triangle or not. Print 'YES' if a triangle is right angled triangle or 'NO' if it's not.

Input:
3
4
5

Output
YES


Python Code :


# Taking input of the three sides of the triangle

a=int(input())

b=int(input())

c=int(input())


# Checking if the given triangle is right angled triangle or not

if a**2 + b**2 == c**2 or a**2 + c**2 == b**2 or b**2 + c**2 == a**2:

    print("YES",end="")

else:

    print("NO",end="")


Explanation:

  1. We take the input of the three sides of the triangle using the input() function and int() function to convert the input string into integers. We store the input values in the variables a, b, and c, respectively.
  2. We use the Pythagorean theorem to check if the given triangle is a right-angled triangle or not. According to the theorem, in a right-angled triangle, the square of the hypotenuse (the longest side) is equal to the sum of the squares of the other two sides.
  3. We check if any of the three possible combinations of a, b, and c satisfy the Pythagorean theorem using the if statement. If any of the combinations are true, we print "YES" indicating that the triangle is a right-angled triangle. Otherwise, we print "NO" indicating that the triangle is not a right-angled triangle.
  4. We use the end parameter in the print() function to print the output in a single line, without adding a newline character at the end.

Note: This code assumes that the input values a, b, and c are positive integers representing the sides of a triangle. If the input values are negative or zero, or if they do not represent the sides of a triangle, the code may produce unexpected results.