is_prime (6/15) - What is wrong?


#1

def is_prime(x):
if x == 0 or x == 1:
return False
elif x == 2:
return True
else:
for n in range(2, x - 1):
if x % n == 0:
return False
else:
return True


#2

What if x is less than 0?

What does the indentation look like on your final return statement? Is inside the if…else? or inside the loop? It should not be inside either block.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.