HomeLanguagesPython | sympy.prevprime() method

Python | sympy.prevprime() method

In sympy module, we can get the previous prime number for a given number n using sympy.prevprime() function. For n < 2^64 the answer is definitive; larger n values have a small probability of actually being pseudoprimes. 
 

Syntax:  sympy.prevprime()
Parameter:  n; number to be tested
Return:  previous prime value

Code #1: 

Python3




# Python program to get previous prime number
# using sympy.prevprime() method
  
# importing sympy module
from sympy import *
  
# calling prevprime function on different numbers
geek1 = prevprime(7)
geek2 = prevprime(13)
  
print(geek1)
print(geek2)


Output: 
 

5
11

Code #2: 

Python3




# Python program to check prime number
# using sympy.prevprime() method
  
# importing sympy module
import sympy.ntheory as nt
  
# calling prevprime function on different numbers
nt.prevprime(2)


Output: 
 

ValueError: no preceding primes

 

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

Most Popular

Dominic
32740 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7125 POSTS0 COMMENTS
Nicole Veronica
12256 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12339 POSTS0 COMMENTS
Shaida Kate Naidoo
7236 POSTS0 COMMENTS
Ted Musemwa
7499 POSTS0 COMMENTS
Thapelo Manthata
7216 POSTS0 COMMENTS
Umr Jansen
7186 POSTS0 COMMENTS