Python Articles

Page 120 of 855

Check if given four integers (or sides) make rectangle in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

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, thenreturn Trueotherwise when sides[0] is same as sides[1] and sides[2] is same as sides[3], thenreturn Trueotherwise when sides[0] is same as sides[3] and sides[2] is same as sides[1], thenreturn Trueotherwise when sides[0] is same as sides[2] and sides[3] ...

Read More

Check if given number is a power of d where d is a power of 2 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 213 Views

Suppose we a number n and another value x, we have to check whether it is a power of x or not, where x is a number power of 2.So, if the input is like n = 32768 x = 32, then the output will be True as n is x^3.To solve this, we will follow these steps −From the main method do the following −cnt := 0if n is not 0 and (n AND (n - 1)) is same as 0, thenwhile n > 1, don = n/2cnt := cnt + 1return cnt mod (log c base 2) is ...

Read More

Check if given number is Emirp Number or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have a number n. We have to check whether n is an Emirp number or not. We all know Emirp number is (letters of prime in backward direction) is a prime number that results in a different prime when its digits are reversed.So, if the input is like n = 97, then the output will be True as the reverse of 97 is 79 which is another prime.To solve this, we will follow these steps −if num is not prime, thenreturn Falsereverse_num := reverse of numreturn true when reverse_num is prime otherwise falseExampleLet us see the following implementation ...

Read More

Check if given number is perfect square in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 8K+ Views

Suppose we have a number n. We have to check whether the number n is perfect square or not. A number is said to be a perfect square number when its square root is an integer.So, if the input is like n = 36, then the output will be True as 36 = 6*6.To solve this, we will follow these steps −sq_root := integer part of (square root of n)return true when sq_root^2 is same as n otherwise falseExampleLet us see the following implementation to get better understanding −from math import sqrt def solve(n):    sq_root = int(sqrt(n))    return ...

Read More

Check if given string can be split into four distinct strings in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 420 Views

Suppose we have a string s, we have to check whether we can split it into four sub-strings such that each of them are non-empty and unique.So, if the input is like s = "helloworld", then the output will be True as one of the possible set of sub-strings are ["hel", "lo", "wor", "ld"]To solve this, we will follow these steps −if size of s >= 10, thenreturn Truefor i in range 1 to size of s - 1, dofor j in range i + 1 to size of s - 1, dofor k in range j + 1 to ...

Read More

Check if is possible to get given sum from a given set of elements in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 507 Views

Suppose we have an array called nums and another value sum. We have to check whether it is possible to get sum by adding elements present in nums, we may pick a single element multiple times.So, if the input is like nums = [2, 3, 5] sum = 28, then the output will be True as we can get 26 by using 5 + 5 + 5 + 5 + 3 + 3 + 2To solve this, we will follow these steps −MAX := 1000table := an array of size MAX ad fill with 0Define a function util() . This ...

Read More

Check if it is possible to convert one string into another with given constraints in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 258 Views

Suppose we have two strings s and t with only three characters 'A', 'B' and '#'. We have to check whether it is possible to convert s into t by performing these operations on s.'A' can move only to the left hand side'B' can move only to the right hand sideNeither 'A' nor 'B' can cross each otherSo, if the input is like s = "##AB##B" t = "A###B#B", then the output will be True as in s A can move easily to the left most position, and middle B can move one step to the rightTo solve this, we ...

Read More

Check if it is possible to create a palindrome string from given N in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 514 Views

Suppose we have a number n. We have to check whether we can create an alphabetical lowercase string from that number and check whether the string is palindrome or not. Here we will take only characters from a to j, [a = 0, b = 1... j = 9]. So if the number is 42 the substring "ec" will be printed till 6 (4+2) characters "ececec" then check this is palindrome or not.So, if the input is like n = 43, then the output will be True the string is "ededede" and this is palindrome.To solve this, we will follow ...

Read More

Check if it is possible to create a polygon with a given angle in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 290 Views

Suppose we have an angle a. We have to check whether we can make a regular polygon where all angles are same as a or not.So, if the input is like a = 120, then the output will be True the pentagon has all angles same as 120°. As we know$$Interior Angle(a)=\frac{180\times(n-2)}{n}\begin{bmatrix} n=number of sides of polygon\end{bmatrix}$$ $$¿n=\frac{360}{180-a}$$So if n is integer then this is forming a regular polygon.To solve this, we will follow these steps −sides := 360 /(180 - a)if sides has no fractional part, thenreturn Truereturn FalseExampleLet us see the following implementation to get better understanding −def ...

Read More

Check if it is possible to create a polygon with given n sidess in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 396 Views

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 numsif last element of ...

Read More
Showing 1191–1200 of 8,547 articles
« Prev 1 118 119 120 121 122 855 Next »
Advertisements