python check if the number is prime code example
Example 1: how to check if a number is prime in python
def prime(num):
for x in range(2,num):
if num % x == 0:
return False
return True
Example 2: how to check if a number is prime in python
import math
def prime(x):
if x == 2 or x == 3 or x==5:
return True
if x == 1 or x == 4:
return False
num = 2
a= math.sqrt(x)+4
while a > num:
if x % num == 0:
return False
else:
num = num + 1
return True