
- 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 if given four integers (or sides) make rectangle in Python
Suppose we have a list of four sides, we have to check whether these four sides are forming a rectangle or not.
So, if the input is like sides = [10, 30, 30, 10], then the output will be True as there are pair of sides 10 and 30.
To solve this, we will follow these steps −
- if all values of sides are same, then
- return True
- otherwise when sides[0] is same as sides[1] and sides[2] is same as sides[3], then
- return True
- otherwise when sides[0] is same as sides[3] and sides[2] is same as sides[1], then
- return True
- otherwise when sides[0] is same as sides[2] and sides[3] is same as sides[1], then
- return True
- return False
Example
Let us see the following implementation to get better understanding −
def solve(sides): if sides[0] == sides[1] == sides[2] == sides[3]: return True elif sides[0] == sides[1] and sides[2] == sides[3]: return True elif sides[0] == sides[3] and sides[2] == sides[1]: return True elif sides[0] == sides[2] and sides[3] == sides[1]: return True return False sides = [10, 30, 30, 10] print(solve(sides))
Input
[10, 30, 30, 10]
Output
True
- Related Articles
- Check whether triangle is valid or not if sides are given in Python
- Check if a point lies on or inside a rectangle in Python
- Check if given string can be split into four distinct strings in Python
- Check if given four points form a Square
- Maximum area rectangle by picking four sides from array in C++
- How To Check if a Triangle is Valid or Not When Sides are Given in Java?
- Check if given number is Emirp Number or not in Python
- Check if the given number is Ore number or not in Python
- Python - Check if a given string is binary string or not
- How To Check if a Given Point Lies Inside a Rectangle in Java?
- Check if array contains contiguous integers with duplicates allowed in Python
- Python program to check if a given string is Keyword or not
- Python - Check if the Pandas Index only consists of integers
- Program to check if the given list has Pythagorean Triplets or not in Python
- Program to check whether we can make k palindromes from given string characters or not in Python?

Advertisements