whats wrong with my code?: def is_prime(x): for n in range(x - 1): if n < 2: return False elif x % n == 0: return False else: return True
i would write the condition for the low numbers:
if n < 2: return False
outside the loop. Also, a function ends the moment a return keyword is reached. Which in your case happens in the first run of the loop. you might want to indent else/return True so that it only returns True after the loop is finished, so you know for sure you have a prime number.