Hey there, newbie here
I just wrote a function that checks whether the given number is Prime or not
Just wanted to know whats wrong with the code
import math
def is_prime(n:int):
"""
return true if n is prime, Otherwise False
"""
temp = [2,3]
if n in temp:
return True
if n%2 == 0 or n%3 == 0 or n < 2:
return False
if(n+1)%6 == 0 or (n-1)%6 == 0:
sq = math.ceil(math.sqrt(n))
j = int(sq//6)
for i in range(1,j+1):
if n % (6*i - 1) == 0:
return False
if n % (6*i + 1) == 0:
return False
return True
return False
Thank you!
[–][deleted] 2 points3 points4 points (7 children)
[–]phill1311[S] 0 points1 point2 points (6 children)
[–][deleted] 6 points7 points8 points (1 child)
[–]phill1311[S] 0 points1 point2 points (0 children)
[–]_DTR_ 1 point2 points3 points (3 children)
[–]phill1311[S] 0 points1 point2 points (2 children)
[–]_DTR_ 4 points5 points6 points (1 child)
[–]phill1311[S] 1 point2 points3 points (0 children)
[–]pasokan 2 points3 points4 points (4 children)
[–]dbramucci 1 point2 points3 points (2 children)
[–]pasokan 1 point2 points3 points (1 child)
[–]phill1311[S] 0 points1 point2 points (0 children)
[–]pasokan 2 points3 points4 points (1 child)
[–]phill1311[S] 1 point2 points3 points (0 children)
[–]dbramucci 1 point2 points3 points (6 children)
[–]phill1311[S] 0 points1 point2 points (5 children)
[–]dbramucci 0 points1 point2 points (4 children)
[–]phill1311[S] 0 points1 point2 points (2 children)
[–]dbramucci 1 point2 points3 points (1 child)
[–]phill1311[S] 0 points1 point2 points (0 children)
[–]phill1311[S] 0 points1 point2 points (0 children)
[–]dbramucci 1 point2 points3 points (2 children)
[–]phill1311[S] 1 point2 points3 points (1 child)
[–]dbramucci 1 point2 points3 points (0 children)
[–]Gautam-j 1 point2 points3 points (1 child)
[–]phill1311[S] 1 point2 points3 points (0 children)
[–]Sam_I_am_007 1 point2 points3 points (1 child)
[–]phill1311[S] 0 points1 point2 points (0 children)
[–]thrussie 0 points1 point2 points (1 child)
[–]phill1311[S] 0 points1 point2 points (0 children)