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