Why does this fail on x=2?

I’m stuck. This is what I have:

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

Your function fails on is_prime(2). It returns None when it should return True.

None indicates the absence of a return value, so for x=2, we don’t get a return value. Which return value did you expect? And why doesn’t your code get there?