
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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
- Related Articles
- Check whether right angled triangle is valid or not for large sides in Python
- How To Check if a Triangle is Valid or Not When Sides are Given in Java?
- Program to check whether given list is in valid state or not in Python
- Check whether a string is valid JSON or not in Python
- Check whether the given numbers are Cousin prime or not in Python
- Program to check whether a board is valid N queens solution or not in python
- Check whether the given string is a valid identifier in Python
- Program to check whether given graph is bipartite or not in Python
- Check whether the given number is Euclid Number or not in Python
- Check whether the given number is Wagstaff prime or not in Python
- Check whether two strings are equivalent or not according to given condition in Python
- Python program to check whether a given string is Heterogram or not
- Program to check whether given matrix is Toeplitz Matrix or not in Python
- Program to check whether given number is Narcissistic number or not in Python
- Program to check whether given tree is symmetric tree or not in Python

Advertisements