The problem is that you put return False
in the else
clause rather than at the end of the function. So your function will return right after the first divisor is checked, rather than going on to check other divisors.
Here is a simple primality test similar to yours:
def is_prime(n):
d = 2
while d * d <= n:
if n % d == 0:
return False
d += 1
return n > 1