You're going to return from the first iteration of that for loop whether you're done checking or not. You shouldn't return from inside the loop unless the number is definitely not prime. Remove the else
and only return True
if the loop finishes.
def eprimo(num):
if num < 2:
return False
if num == 2:
return True
else:
for div in range(2,num):
if num % div == 0:
return False
return True
Optimization side note: You really don't need to check all the divisor candidates up to num
. You only need to check up to the square root of num
.