Python | sympy.prevprime() method
Last Updated :
08 Feb, 2023
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
from sympy import *
geek1 = prevprime( 7 )
geek2 = prevprime( 13 )
print (geek1)
print (geek2)
|
Output:
5
11
Code #2:
Python3
import sympy.ntheory as nt
nt.prevprime( 2 )
|
Output:
ValueError: no preceding primes
Share your thoughts in the comments
Please Login to comment...