I initially had my range at (2, x-1) but after reading another question I realized it was not inclusive so I changed it to (2,x). After that, my code worked for is_prime(3) (it hadn't been until then). But now, it still doesn't work for is_prime (9), and returns the error message "Oops, try again. Your function fails on is_prime(9). It returns True when it should return False."
It should return False, I know that, but I don't understand why the code isn't running the number correctly. Help would be appreciated.
def is_prime(x): if x < 2: return False elif x == 2: return True for n in range(2, x): if x % n == 0: return False elif x % n != 0: return True else: return False