Python | simpy.primerange () method

Python Methods and Functions

In the simpy module, we can get a list of all primes in the range [a, b) using sympy.primerange () .

  Syntax:  sympy.primerange ()  Parameter:  range a and b  Return:  a list of all primes in given range 

Code # 1:

# Python program to get a range of prime numbers
# using the sympy method .primerange ()

 
# import sympy module

from sympy import *

  
# call a simple function on different numbers

list (primerange ( 7 , 30 ))

list (primerange ( 0 , 100 ))

Output:

[7, 11, 13, 17, 19, 23 , 29]
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

Code # 2:

# Program Python to get prime range prime number
# using sympy.primerange () method

 
# importing the sympy module

import sympy.nt heory as nt

 
# call a simple range function in a range

list (nt.primerange ( 2 , 31 ))

Output:

 [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] 




Get Solution for free from DataCamp guru