Is_prime function


def factorial(x):
is_prime = False
if x == 1: return False
elif x == 0 or x < 0: return False
elif x == 2 or x == 3: return True
n = x
while n > 3:
if x%2 == 0 or (x%n == 0 and x!= n):
n -= 1
is_prime = False
n -= 1
is_prime = True
return is_prime

Can someone please tell me why I get the warning :'Your function crashed because you were trying to divide or modulo (%) by zero.'

Please note, I have found a different way of doing the problem so I am not interested in alternate solutions; just how n could ever be 0 (and produce the error) when I have the condition while n > 3 out side the modulo check?


Hello, @robinbogan!
I checked your code and, besides the indentation, everything seems to be correct.
I've tested your code on another compiler and got the expected output for the input zero.

Try refreshing the page and executing.

Best regards,


Never mind. I stupidly had the function named as factorial from the last test. Remove this and it solves the issue even though the code is wrong