def is_prime(x):

if x < 2:

return False

elif x == 2:

return True

elif x == 3:

return True

else:

for i in range(2, x):

if x % i == 0:

return False

else:

return True

Why this code doesn't work and the next one does?

def is_prime(x):

if x < 2:

return False

elif x == 2:

return True

elif x == 3:

return True

else:

for i in range(2, x):

if x % i == 0:

return False

return True

Why the return True in the second one have to be outside the for loop? Shouldn't it be inside?