Python | sympy.is_prime () method

Python Methods and Functions

Note that negative numbers (such as -13) are not considered prime numbers.

  Syntax:  sympy.is_prime ()  Parameter:  n; number to be tested  Return:  bool value result 

Code # 1:

# Python program to test a prime number
# using the sympy.is_prime () method

  
# import sympy module

from sympy import *

 
# calling the isprime function for different numbers

geek1 = simplify ( 30 ). is_prime

geek2 = simplify ( 13 ). is_prime

 

print (geek1)

print (geek2)

Output:

 False True 

Code # 2:

# Python program to check prime number
# using the sympy.is_prime () method

 
# import sympy module

from sympy import *

 
# calling the isprime function for different numbers

geek = simplify ( 2 ). is_prime

 

print (geek)

Output:

 True 




Get Solution for free from DataCamp guru