Is_prime


#1

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

error-Oops, try again. Your function fails on is_prime(-10). It returns True when it should return False.

pls help me with this


#2

here:

if x==0 or x==1:

you should simply check for values lesser then 2, this way, you also cover all negative numbers (which are not prime numbers)


#3

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