Sunday, December 29, 2024
Google search engine
HomeLanguagesPython | sympy.is_prime() method

Python | sympy.is_prime() method

In the sympy module, we can test whether a given number n is prime or not using sympy.is_prime() function. For n < 2^64 the answer is definitive; larger n values have a small probability of actually being pseudoprimes. 

Note that Negative numbers (e.g. -13) are not considered prime numbers.

Syntax:  sympy.is_prime()
Parameter:  n; number to be tested
Return:  bool value result 

Code #1:  

Python3




# Python program to check prime number
# using sympy.is_prime() method
 
# importing sympy module
from sympy import *
 
# calling isprime function on different numbers
geek1 = simplify(30).is_prime
geek2 = simplify(13).is_prime
 
print(geek1)
print(geek2)


Output: 

False
True

Code #2:  

Python3




# Python program to check prime number
# using sympy.is_prime() method
 
# importing sympy module
from sympy import *
 
# calling isprime function on different numbers
geek1 = simplify(2).is_prime
geek2 = simplify(-2).is_prime
 
print(geek1)
print(geek2)


Output: 

True
False
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