 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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 triangle is valid or not if sides are given in Python
Suppose we have three sides. We have to check whether these three sides are forming a triangle or not.
So, if the input is like sides = [14,20,10], then the output will be True as 20 < (10+14).
To solve this, we will follow these steps −
- sort the list sides
- if sum of first two sides <= third side, then- return False
 
- return True
Let us see the following implementation to get better understanding −
Example Code
def solve(sides): sides.sort() if sides[0] + sides[1] <= sides[2]: return False return True sides = [14,20,10] print(solve(sides))
Input
[14,20,10]
Output
True
Advertisements
 