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


#1

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
  else:
    return False

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


#2

This will return false positives.

if x % n == 0:
    return False

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


#3

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