Found 27104 Articles for Server Side Programming

How do I find the largest integer less than x in Python?

Jayashree
Updated on 27-Oct-2022 12:23:22

2K+ Views

In this article, we will show you how to find the largest integer less than x in python. The Greatest Integer Function [X] denotes an integral part of the real number x that is the closest and smallest integer to x. It's also called the X-floor. [x]=the largest integer less than or equal to x. Generally If n

How to check whether a number is prime or not using Python?

Jayashree
Updated on 02-Mar-2020 10:06:49

709 Views

Principle used in following solution to this problem is to divide given number with all from 3 its square root, a number's square root is largest possible factor beyond which it is not necessary to check if it is divisible by any other number to decide that it is prime number.The function returns false for all numbers divisible by 2 and less than 2. For others return value of all) function will be false if it is divisible by any number upto its square root and true if it is not divisible by any numberExampledef is_prime(a):     if a ... Read More

How to Multiply Two Matrices using Python?

Jayashree
Updated on 02-Mar-2020 10:08:06

3K+ Views

Multiplication of two matrices is possible only when number of columns in first matrix equals number of rows in second matrix.Multiplication can be done using nested loops. Following program has two matrices x and y each with 3 rows and 3 columns. The resultant z matrix will also have 3X3 structure. Element of each row of first matrix is multiplied by corresponding element in column of second matrix.ExampleX = [[1, 2, 3],          [4, 5, 6],          [7, 8, 9]]     Y = [[10, 11, 12],         [13, 14, 15], ... Read More

How to Transpose a matrix in Single line in Python?

Vikram Chiluka
Updated on 27-Oct-2022 13:12:50

2K+ Views

In this article, we will show you how to transpose a matrix in a single line in python. Below are the various ways to accomplish this task − Using Nested List Comprehension Using NumPy Module Using zip() Function What is the transpose of the matrix? A matrix transpose is the interchanging of rows and columns. It is abbreviated to A'. The element in the ith row and jth column of A' will be moved to the jth row and ith column of A' Using Nested List Comprehension Algorithm (Steps) Following are the Algorithm/steps to be followed to ... Read More

How to Convert Decimal to Binary Using Recursion in Python?

Vikram Chiluka
Updated on 27-Oct-2022 12:37:31

2K+ Views

In this article, we will show you how to convert decimal to binary using recursion in python. A decimal number is the most familiar number system to the general public. It is base 10 which has only 10 symbols − 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Whereas Binary number is the most familiar number system to digital systems, networking, and computer professionals. It is base 2 which has only 2 symbols: 0 and 1, these digits can be represented by off and on respectively. When we convert a number from the decimal number system to ... Read More

What is random.uniform method in Python?

Jayashree
Updated on 24-Jun-2020 07:00:09

118 Views

The uniform() function is defined in the random module of the standard Python library. It returns a random floating-point number between a given range of numbers>>> import random >>> random.uniform(10,100) 20.118467024396452 >>> random.uniform(10,100) 23.739576765885502

How to randomize the items of a list in Python?

Jayashree
Updated on 24-Jun-2020 06:59:23

1K+ Views

The random module in the Python standard library provides a shuffle() function that returns a sequence with its elements randomly placed.>>> import random >>> l1=['aa',22,'ff',15,90,5.55] >>> random.shuffle(l1) >>> l1 [22, 15, 90, 5.55, 'ff', 'aa'] >>> random.shuffle(l1) >>> l1 ['aa', 'ff', 90, 22, 5.55, 15]

How to shuffle a list of objects in Python?

Vikram Chiluka
Updated on 28-Oct-2022 11:42:21

8K+ Views

In this article, we will show you how to shuffle a list of objects in python. Below are the various methods to accomplish this task: Using random.shuffle() function Using random.sample() function Using Fisher–Yates shuffle Algorithm Using random.randint() and pop() function Assume we have taken a list containing some elements. We will shuffle the elements of the list randomly using different methods as specified above. Using random.shuffle() function The shuffle() method in the random module is used to shuffle a list. It takes a sequence, such as a list, and reorganizes the order of the items. This ... Read More

How can I generate random integers between 0 and 9 using Python?

Vikram Chiluka
Updated on 28-Oct-2022 11:23:17

3K+ Views

In this article, we will show you how to generate random integers between 0 and 9 in Python. Below are the various methods to accomplish this task: Using randint() method Using randrange() method Using secrets module To generate random integers within certain ranges, Python supports a variety of functions. We will discuss Python's built-in random module for generating random numbers. The two primary functions provided by the random module to produce random integers are randint() and randrange(). In order to produce random values, a second module called secrets is also used. Using randint() method The random.randint() method is ... Read More

Why do we use random.seed() in Python?

Jayashree
Updated on 24-Jun-2020 06:56:39

208 Views

The seed() method of random module initializes the random number generator.random.seed(a,b)If a is omitted or None, the current system time is used. If randomness sources are provided by the operating system, they are used instead of the system timeIf a is an int, it is used directly.With version 2 (the default), a str, bytes, or bytearray object gets converted to an int and all of its bits are used.With version 1 (provided for reproducing random sequences from older versions of Python), the algorithm for str and bytes generates a narrower range of seeds.

Advertisements