Why does the following code fail at -10?

def is_prime(x):

if x == 0 or x == 1:

return False

elif x == 2:

return True

else:

for number in range(2, x):

if x % number == 0:

return False

return True

Why does the following code fail at -10?

def is_prime(x):

if x == 0 or x == 1:

return False

elif x == 2:

return True

else:

for number in range(2, x):

if x % number == 0:

return False

return True

negative numbers canâ€™t be prime numbers, so for negative numbers false must be returned

How do you think your code is currently handling that?

1 Like