- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
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
Advertisements