sympy library?sympy is library that is used for symbolic mathematics.
pip can be used to install sympy. Refer to the following command:
pip install sympy
isprime methodThe isprime method is used to determine whether the given number is a prime number or not. This method is intended to be used for integers. Any floating-point numbers (limited precision numbers) will result in False. Negative numbers are not considered prime numbers.
sympy.isprime(n)
n: This is the number that needs to be tested.The isprime method returns True if the given positive integer is a prime number. Otherwise, it returns False.
import sympynum = 19print("sympy.isprime(%s) = %s" % (num, sympy.isprime(num)))num = 19.00print("sympy.isprime(%s) = %s" % (num, sympy.isprime(num)))num = -3print("sympy.isprime(%s) = %s" % (num, sympy.isprime(num)))
sympy module.num.num is a prime number or not by using the isprime method.The output indicates that the isprime method returns False for floating-point numbers and negative numbers.