Oops, try again. Your function fails on is_prime(0). It returns None when it should return False.

Why is it failing on argument(0) and am I doing this correctly?

Oops, try again. Your function fails on is_prime(0). It returns None when it should return False.

Why is it failing on argument(0) and am I doing this correctly?

It asks

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.

?

Hi,

You use x % n = 0, when you should check if `x % number == 0`

. n is the list you are iterating over.

Also look at this:

Your code would be easier to read if you just did it like this:

```
for number in range(2,x-1):
#...
```

Thank you. I realized that I needed to deal with 0 and 1 before anything which made everything else a lot clearer!

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