Python uses the evaluate method to calculate all prime numbers smaller than the given number. python prime numbers
The example in this article shares with you the specific code for python to calculate all prime numbers smaller than the given number for your reference. The details are as follows:
Code Syntax: first, list all candidate numbers in a specified range, and then select a number from the beginning to the end to remove all the numbers in the future. The number that can be divisible is certainly not a prime number, and these numbers are filtered out, repeat the process until the selected divisor is greater than the square root of the maximum number. The Code mainly demonstrates the use of built-in functions such as filter () and slice. In fact, this algorithm is not very efficient.
Def primes2 (maxNumber): '''' obtain all prime numbers smaller than maxNumber ''' # list (range (3, maxNumber, 2) of the integer to be judged )) # square root of the maximum integer m = int (maxNumber ** 0.5) for index in range (m): current = lst [index] # If the current number is greater than the square root of the maximum integer, end judgment if current> m: break # filter the elements after the position lst [index + 1:] = list (filter (lambda x: 0 if not x % current else x, lst [index + 1:]) #2 is also the prime number return [2] + lst
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.