I bet you hear this a lot - but something's wrong with my code


Hey guys,
I'm in the is_prime task... and can't figure out what i did wrong.
I even wrote in plain English what every line is doing (a suggestion i found here in the forum - so thanks) and still can't understand what's wrong with my code

 def is_prime(x):        
>     if x ==0 or x == 1:         #if x is 0 or 1 - return False
>         return False
>     elif x ==2:                     #if x is 2 - return True
>         return True
>     else:                             #if none of those apply
>         for n in range(1,x):      #Check in range btw 1 and x
>             if (x%n)==0:           #to see if any of the numbers in range are devisable
>                 return False
>         else:                         # if you can't find any - return True
>             return True


from the instructions:

For each number n from 2 to ....

you use 1 to ....


Now it tells me:

Your function fails on is_prime(-10). It returns True when it should return False.


from the hint:

Remember: all numbers less than 2 are not prime numbers!

this includes all negative numbers, maybe you should write code to deal with this?


Thanks a lot for your quick help :slight_smile: