6/15 is_prime


#1

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
  else:
    n = 2
    while n < x:
      if x % n == 0:
        return False
      else:
        n += 1
    return True

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


#2

I ran your code here:

https://repl.it/@stetim94/SandybrownDeepskyblueTahr

it seems to work fine.


#3

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.


#4

Maybe refresh the codecademy page?


#5

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