This is the function I originally wrote:
def is_prime(x): if x < 2: return False elif x == 2 or x == 3: return True else: for n in range(2, x-1): if x % n == 0: return False else: return True
I understand to correct this function and make it work I need to remove the last "else" statement and fix the indentation for the last "return True". What I do not understand is why the function I pasted above works on most numbers but fails when you pass it 9, 15, and 21 (21 being highest number I tested it to). What is it about the improperly formatted else & return true statements that cause the function to return the proper result for say 17, 18, 19, and 20, but then fail for 21?