Open In App

Python | sympy.primepi() method

Last Updated : 26 Aug, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

With the help of sympy.primepi() method, we can find the number of prime numbers less than or equal to a given number.

Syntax: primepi(n)

Parameter:
n – It denotes the number up to which the count of prime number is calculated.

Returns: Returns the number of prime numbers less than or equal to n.

Example #1:




# import primepi() method from sympy
from sympy import primepi
  
n = 10
  
# Use primepi() method 
count_primes = primepi(n) 
      
print("The number of prime numbers less than or equal to {} is {}".format(n, count_primes))


Output:

The number of prime numbers less than or equal to 10 is 4

Example #2:




# import primepi() method from sympy
from sympy import primepi
  
n = 150
  
# Use primepi() method 
count_primes = primepi(n) 
      
print("The number of prime numbers less than or equal to {} is {}".format(n, count_primes))          


Output:

The number of prime numbers less than or equal to 150 is 35

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads