is_prime help please!


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

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

I expected this to work, because I followed the directions.

```python

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

<do not remove the three backticks above>

#2

No, this is not working. Why not? A function ends the moment a return keyword reached. In your first run of your for loop, a return keyword is reached (either if is true, or else executes)

You might want to put else outside the for loop (or remove the else all together, and put return True outside the for loop)

You might then want to include a return false for everything lower then 2 (two included)


#7

Hi, there are a few problems in your code.

First, you missed the situation when x is smaller than 2. The smallest prime number is 2. You need an extra statement to rule out the numbers smaller than 2.

Then you shou use range(2,x) instead of range(2, x - 1). The stop will not be contained in the list and you get a list from 2 to x-1.