Articles

primePy python module - methods

primePy python module - methods


In this primepy tutorial, we will discuss the methods that are present in this module.

Introduction

primePy is a module in python used to perform operations on prime numbers. It will be helpful to us to search or deal with prime numbers.

We have to install primePy module to use this.

Syntax:

pip install primePy

After Installation you will get this:

Collecting primePy
  Downloading primePy-1.3-py3-none-any.whl (4.0 kB)
Installing collected packages: primePy
Successfully installed primePy-1.3

primepy python methods are explained below:

 

Method 1 : primes.check()

primes is available in primePy  and check() method is used to check whether the given number is prime or not.

If the number is prime, it will return True,otherwise False.

Syntax:

primes.check(number)

where, number is an input number.

Example:

In this program we are checking with 5 numbers , they are prime or not.

#import primes from primePy
from primePy import primes

#check 5 is prime or not
print(primes.check(5))

#check 15 is prime or not
print(primes.check(15))

#check 25 is prime or not
print(primes.check(25))

#check 56 is prime or not
print(primes.check(56))

#check 97 is prime or not
print(primes.check(97))

Output:

True
False
False
False
True

Method 2 : primes.first()

primes is available in primePy  and first() method is used to return the first n prime numbers. where n is an integer specified as an argument.

Syntax:

primes.first(number)

where, number is an input number.

Example:

In this program we are displaying first n prime numbers with 2 values.

#import primes from primePy
from primePy import primes

#get first 5 numbers
print(primes.first(5))

#get first 50 numbers
print(primes.first(50))

Output:

From the above code, we are displaying first 5 primes and 50 primes.

[2, 3, 5, 7, 11]
[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, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229]

Method 3 : primes.upto()

primes is available in primePy  and upto() method is used to return the  prime numbers upto the specified n value. where n is an integer specified as an argument.It will print the primes less than or equal to n.

Syntax:

primes.upto(number)

where, number is an input number.

Example:

In this program we are displaying the prime numbers upto 45.

#import primes from primePy
from primePy import primes


#get upto 45 prime numbers
print(primes.upto(45))

Output:

prime numbers upto 45 are returned.

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]

Method 4 : primes.between()

primes is available in primePy  and between() method is used to return the  prime numbers specified in the given range. It will take two values, first value specifies the starting range and second value specify the ending range

Syntax:

primes.upto(start,end)

Example:

In this program we are displaying the prime numbers that are in between 56 and 190.

#import primes from primePy
from primePy import primes


#get prime numbers  from  56 to 190
print(primes.between(56,190))

Output:

prime numbers  from 56 to 190 are returned

[59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181]

This wraps up our session primepy python.


Python Numbers Program

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Gottumukkala Sravan Kumar 171FA07058
B.Tech (Hon's) - IT from Vignan's University. Published 1400+ Technical Articles on Python, R, Swift, Java, C#, LISP, PHP - MySQL and Machine Learning
Page Views :    Published Date : Jun 12,2023  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!