-7 return True in Prime number : is it incorrect?



I stuck when I tested the prime number when it take -7 and it return True : And then my console said "Your function fails on is_prime(-7). It returns True when it should return False."

-7 is prime number and should return True, not answer suggestion that it should return False

def is_prime(x):
    x = abs(x)
    if x < 2:
            return False
    for n in range(2, x, 1):
        if x % n == 0:
            return False
    return True


oops, why do you use abs? You can simple remove abs, and the steps from your for loop:

for n in range(2, x):

range will take steps from 1, or -1 if x is smaller then 2


Negative numbers are not considered to be prime. Your code should ensure that x is greater than one.


It's been an eternity waiting for this to come up!


Thank you.
So it was my misconception about prime number, not about the way program compute then.