Oops, try again. Your function fails on is_prime(4). It returns True when it should return False.
I expected my function to return False,indicating that 4 is not a prime number. But instead it keeps returning True.
I have divided my function into four parts:
first part checks if it the number is greater than 1 (because all integers less than 2 are not prime numbers)
second part checks if modulo of the number divided by one and itself is equal to 0 (which is required for prime numbers)
third part should check if modulo of any number in the range (2,the number) is 0, if so, it should return False, indicating the number is not a prime number
Fourth part checks if all three conditions are met.
Yet, there seems to be an issue in the third part, I think.
def is_prime(x): if x > 1: req1 = True else: req1 = False return req1 if (x % 1 == 0) and (x % x == 0): req2 == True else: req2 == False return req2 y = range(2,x-1) req3 = True for i in y: if x % i == 0: req3 = False return req3 if (req1 == True) and (req2 == True) and (req3 == True): return True else: return False is_prime(4)