def is_prime(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
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



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)


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