sympy library?sympy is a library we use for symbolic mathematics in Python.
We use pip to install sympy. Let’s refer to the following command:
pip install sympy
nextprime methodThe nextprime method returns the ith prime number greater than the given number, where i is an integer.
The default value for i is 1. So, the nextprime method returns the first prime number greater than the given number.
Let’s view the syntax of nextprime method.
sympy.nextprime(n, ith=1)
n: This represents any number.ith: This indicates the ordinal prime number greater than n to be retrieved.The method returns the ith prime number greater than n.
Let’s view the code below:
import sympyn = 100ith = 5print("sympy.nextprime(%s, %s) = %s" % (n, ith, sympy.nextprime(n, ith)))
sympy package.n.i.ith prime number larger than n using the sympy.nextprime() method.