is_Prime


#1

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

`
I get the error below and I am unsure what to change
Oops, try again. Your function fails on is_prime(1). It returns None when it should return False.


#2

All numbers less than 2 should return false.
so change the first if statement from x==0 to x<2


#3

you should use "while...break"


#4

import math
def is_prime(x):
if x==0 or x==1 or x<0:
return False
if x % 2 == 0 and x > 2:
return False
return all(x % i for i in range(3, int(math.sqrt(x)) + 1, 2))


#5

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