Is_prime


#1

I get the following error - Your function fails on is_prime(-7). It returns True when it should return False. Can someone please help?

def is_prime(x):
#no other number goes in except 1 and number itself
x = abs(x)
if x < 2:
return False
if x == 2:
return True
for n in range(2, x):
if x % n == 0:
return False
else:
return True


#2

why do you use abs()?


#3

I agree with elma, why do you use abs()?
I guess you want to consider negative numbers.
In my opinion, I think you only should consider prime, without this range you turn other results to False by using 'else'.
That would be enough.