Is_prime having trouble getting it to work


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

<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?>


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

<do not remove the three backticks above>


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


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