6/15 is_prime


I’m getting stuck on an infinite loop when I try this:

def is_prime(x):
  if x < 2:
    return False
  elif x == 2:
    return True
    n = 2
    while n < x:
      if x % n == 0:
        return False
        n += 1
    return True

Which doesn’t make sense to me. Any suggestions? Thank you``


I ran your code here:


it seems to work fine.


weird, thanks! Frustrating that I can’t get it to work in the codecademy editor but nice to see that I wasn’t just screwing it up in some unknown way.


Maybe refresh the codecademy page?


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