6/15 my code is wrong but an error never comes up?


I don’t know whats wrong with my code?

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

I just would like someone to explain to me why this doesn’t work.


This will return false positives.

if x % n == 0:
    return False

Now it only returns inside the loop if a factor is found.


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