Programming Articles - Page 951 of 3366

Python Pandas - Check if an Interval is closed on the right side

AmitDiwan
Updated on 20-Oct-2021 08:06:24

191 Views

To check if an Interval is closed on the left side, use the interval.closed_right property. At first, import the required libraries −import pandas as pdInterval set using the "closed" parameter with value "right" i.e. [0, 5) is described by 0 < x

Program to find out the sum of the number of divisor of the divisors in Python

Arnab Chakraborty
Updated on 20-Oct-2021 08:00:18

318 Views

Suppose we are given two integer numbers m and a. Now n = p1(a + 1) *p2(a + 2) *...*pm(a + m), where pi is the i-th prime number and i > 0. We have to find the value of k, where k = summation of f(x) values of n. Here f(x) values are the number of divisor values of each divisor of n.So, if the input is like m = 2, a = 1, then the output will be 60.So, n = 2^2 x 3^3n = 4 x 27n = 108The divisors of 108 are: 1, 2, 3, 4, ... Read More

Program to find out the value of a given equation in Python

Arnab Chakraborty
Updated on 20-Oct-2021 07:58:13

1K+ Views

Suppose we are given five integer numbers a, b, c, d, n. We have to find out ((ab)(cd)) mod n. The output value is an integer number.So, if the input is like a = 2, b = 3, c = 2, d = 4, n = 10, then the output will be 6.2^3 = 8 2^4 = 16 8^16 = 281474976710656 281474976710656 mod 10 = 6To solve this, we will follow these steps −Define a function helper() . This will take np := ni := 2while i * i 1, thenp := p - floor value of (p / ... Read More

Python Pandas - Check whether the interval is closed on the left-side, right-side, both or neither

AmitDiwan
Updated on 20-Oct-2021 07:54:37

176 Views

To check whether the interval is closed on the left-side, right-side, both or neither, use the interval.closed property.At first, import the required libraries −import pandas as pdClosed interval set using the "closed" parameter with value "both". A closed interval (in mathematics denoted by square brackets) contains its endpoints, # i.e. the closed interval [0, 5] is characterized by the conditions 0

Program to find out the length of the substring where two times the number of zeroes in substring is lesser than or equal to three times the number of ones in the substring in Python

Arnab Chakraborty
Updated on 20-Oct-2021 07:54:31

220 Views

Suppose we are given a string and an integer k. The string is repeated k times and made to another string. Our task is to find the length of the substring in the new string where 2 * (number of zeroes in substring) 0:          continue       else:          a = min(k - 1, -tmp // list_a[str_len])       v = a * list_a[str_len] - list_a[i]       b = bisect_left(list_b, (-v + 1, 0)) - 1       res = max(res, temp_list[b] - i + a * str_len)    return res print(solve(2, '0101011'))Input2, '0101011'Output14

Program to find out the value of a power of 2 in Python

Arnab Chakraborty
Updated on 20-Oct-2021 07:47:48

429 Views

Suppose we are given two integer numbers p and q. We have to find out the value of 22^p mod q. The output has to be an integer.So, if the input is like p = 5, q = 6, then the output will be 4To solve this, we will follow these steps −res := 2^(2^p) mod qreturn resExampleLet us see the following implementation to get better understanding −def solve(p, q): res = pow(2, 2 ** p, q) return res print(solve(5, 6))Input5, 6Output4

Program to find out the number of special numbers in a given range in Python

Arnab Chakraborty
Updated on 20-Oct-2021 07:46:48

2K+ Views

Suppose we are given a range of integer numbers and are asked to find out the special numbers in the range. A special number is a number that is a positive integer having only 1 digit in its decimal representation. A number that has more than 1 digit in its decimal representation can also be special if the number is divisible by the count of digits in its decimal representation and the quotient value is itself a special number. We return the count of special numbers in the given range (left_limit, right_limit).So, if the input is like left_limit = 5, ... Read More

Python Pandas - Create a half-closed time interval and check for existence of endpoints

AmitDiwan
Updated on 20-Oct-2021 07:53:37

143 Views

To create a half-closed time interval, use the pandas.Interval() and set the closed parameter to right. To check for existence of endpoints, use the in property.At first, import the required libraries −import pandas as pdHalf-Closed interval set using the "closed" parameter with value "right". Half-Closed i.e. (0, 5] is described by 0 < x

Python Pandas - Create a half-open time interval and check for existence of endpoints

AmitDiwan
Updated on 20-Oct-2021 07:46:05

348 Views

To create a half-open time interval, use the pandas.Interval() and set the closed parameter to left. To check for existence of endpoints, use the in property.At first, import the required libraries −import pandas as pdHalf-Open interval set using the "closed" parameter with value "left". Half-open i.e. [0, 5) is described by 0

Program to find out the number of consecutive elements in a matrix whose gcd is greater than 1 in Python

Arnab Chakraborty
Updated on 20-Oct-2021 07:43:46

213 Views

Suppose we are given a matrix that contains n rows and m columns. We have to find out the largest number of consecutive elements in the matrix where the gcd of the elements is greater than 1. The consecutive elements can either lie horizontally or vertically in the matrix.So, if the input is like37912594678510and m = 4, n = 3; then the output will be 3.The fourth column of the given matrix is 12, 6, 10. The gcd of the elements of this column is 2. As there are three elements, the answer is 3.To solve this, we will follow ... Read More

Advertisements