Is_Prime


#1

Hi!
My code fails with number 4. It returns True. I can't find what is wrong.
Please help!

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


#2

change x%n ==1 to equal to zero.


#3

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