Syntax error Check whether right angled triangle is valid or not for large sides in Python

Check whether right angled triangle is valid or not for large sides in Python



Suppose we have three sides in a list. We have to check whether these three sides are forming a right angled triangle or not.

So, if the input is like sides = [8, 10, 6], then the output will be True as (8^2 + 6^2) = 10^2.

To solve this, we will follow these steps −

  • sort the list sides
  • if (sides[0]^2 + sides[1]^2) is same as sides[2]^2, then
    • return True
  • return False

Let us see the following implementation to get better understanding −

Example Code

Live Demo

def solve(sides):
   sides.sort()
   if (sides[0]*sides[0]) + (sides[1]*sides[1]) == (sides[2]*sides[2]):
      return True
   return False
   
sides = [8, 10, 6]
print(solve(sides))

Input

[8, 10, 6]

Output

True
Updated on: 2021-01-16T04:45:16+05:30

746 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements