This is my first ever post so please be patient if it's not quite structured how it should be, thanks.
So I've taken care of numbers 2 and 3 with simple if statements. Then for 4 and every other number above 3 I've set up a for loop with a nested while loop testing if x can be divided evenly.
The error message states that when x = 4 it is returning none when of course it should return true;
"Oops, try again. Your function fails on is_prime(4). It returns None when it should return False."
I think the while loop is getting stuck and not progressing to the else statement which I could understand if the else function was part of the if statement, however it is outside of the if statement and is part of the for loop, therefore it shouldn't get stuck. I've also tried indenting the else statement under the while loop but to no avail. Otherwise I have no idea as to what could be going wrong here. Any suggestions?
def is_prime(x): if x < 2: return False if x == 2 or x == 3: return True else: for n in range(x - 1, 2): while n > 1: if x % n == 0: return False else: return True