Stuck on the 'is_prime' class


#1

Hi All,

I am stuck at the ‘is_prime’ class under ‘Practice Makes Perfect’.

I receive no error messages, nothing seems to happen with I run this program

The function should be evaluated with candidate prime numbers, here is the code, what am
I doing wrong? Noting happens when I run this program.

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

#2

I think I see the problem… i’m not incrementing ‘n’… causing an infinite loop condition…

oops…


#3

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