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


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/6

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


#2

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


#3

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


#4

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


#5

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