Sunday, November 17, 2024
Google search engine
HomeLanguagesPython sympy | sieve.primerange() method

Python sympy | sieve.primerange() method

With the help of sympy.sieve.primerange() method, we can generate all prime numbers for a given range [a, b). It returns a type generator object which can be converted to a list for further operations.

Syntax: sieve.primerange(a, b)
Parameters:
a – It denotes the start of the range. It is inclusive.
b – It denotes the end of the range. It is not inclusive.
Returns: The method returns a type generator object.

Example #1:




# import sympy 
from sympy import sieve
  
# Use sieve.primerange() method 
prime_gen = sieve.primerange(1, 10
prime_list = list(prime_gen)
      
print("Prime numbers for the range of numbers [1, 10) : {}".format(prime_list))  


Output:

Prime numbers for the range of numbers [1, 10) : [2, 3, 5, 7]

Example #2:




# import sympy 
from sympy import sieve
  
# Use sieve.primerange() method 
prime_gen = sieve.primerange(8, 50
prime_list = list(prime_gen)
      
print("Prime numbers for the range of numbers [8, 50) : {}".format(prime_list))      


Output:

Prime numbers for the range of numbers [8, 50) : [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments