Optimized prime check code in Python.

This commit is contained in:
dheerajreddymumma 2018-10-28 16:53:56 +05:30
parent 4e0184a41d
commit 2040757751

View File

@ -1,12 +1,8 @@
import math
def primeCheck(number):
prime = True
for i in range(2, int(number**(0.5)+1), 2):
if i != 2:
i = i - 1
if number % i == 0:
prime = False
break
return prime
if n % 2 == 0 and n > 2:
return False
return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2))
def main():
print(primeCheck(37))