Why doesn't -10 work?

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
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