Your function fails on is_prime(0)


Define a function called is_prime that takes a number x as input.

For each number n from 2 to x - 1, test if x is evenly divisible by n.

If it is, return False.

If none of them are, then return True.def is_prime(x):
for n in range(2,x-1):
if x%n==0:
return False

getting this => “Your function fails on is_prime(0). It returns None when it should return False.”

6/15. is_prime()

To test for zero (or anything less than 2) start with a conditional…

if x < 2: return False

The if statement should not have an else clause. Once the loop is complete, then return True on the last line of the function. Be sure it is only indented one level, and not inside the loop.


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