Is_prime having trouble getting it to work


#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/isprime?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
I get the following error message
Your function fails on is_prime(3). It returns None when it should return True.
I think for some reason I cannot get the code to go past line 6, please help!

this is the code

<What do you expect to happen instead?>

```python

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

<do not remove the three backticks above>

#2

your for loop is causing it. with is_prime(3) that line evaluates to:
for n in range(2,2)
but range is (start number, up to but not including start number) so it starts at 2 but stops at 1 so it never runs. you need to change x-1 to just x


#3

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