Is_prime doesnt work for is_prime(9)


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

beacause 9 % 3 = 0 it should return False

Replace this line with your code. 
def is_prime(x):
    if x < 2:
       return False
    elif x == 2:
         return True
         for n in range(2,x):
             if x % n == 0:
                return False
                  return True


those lines should not be inside the loop. Drop the else and move the return all the way to the left (of the code block, line up with first if).

These three lines are not necessary:

2 will not fit the range of the loop so will drop down to the bottom.


Thank you, i was stuck with this exercise for days :smiley:


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