
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
Check if it is possible to create a polygon with given n sidess in Python
Suppose we have an array nums that contain the size of n sides. We have to check whether we can form a polygon with all of the given sides or not.
So, if the input is like nums = [3, 4, 5], then the output will be True because there are three sides and sum of any two sides is larger than the 3rd one. To solve this, we will use this property where length of one side is smaller than the sum of all other sides.
To solve this, we will follow these steps −
- sort the list nums
- if last element of nums < sum of all elements in nums except last one, then
- return True
- return False
Example
Let us see the following implementation to get better understanding −
def solve(nums): nums.sort() if nums[-1] < sum(nums[:-1]): return True return False nums = [3, 4, 5] print (solve(nums))
Input
[3, 4, 5]
Output
True
- Related Articles
- Check if it is possible to create a polygon with a given angle in Python
- Check if it is possible to create a palindrome string from given N in Python
- Check if it is possible to draw a straight line with the given direction cosines in Python
- Check if it is possible to convert one string into another with given constraints in Python
- Check if it is possible to form string B from A under the given constraint in Python
- Check if it is possible to serve customer queue with different notes in Python
- Check if it is possible to survive on Island in Python
- Check if it is possible to reach a number by making jumps of two given length in Python
- Check if a triangle of positive area is possible with the given angles in Python
- Check if it is possible to move from (0, 0) to (x, y) in N steps in Python
- Check if it is possible to rearrange a binary string with alternate 0s and 1s in Python
- Check if it is possible to sort the array after rotating it in Python
- Check if is possible to get given sum from a given set of elements in Python
- Check if it is possible to transform one string to another in Python
- Check if it possible to partition in k subarrays with equal sum in Python

Advertisements