it does not work for odd numbers

I expect it to work properly

Replace this line with your code.
def is_prime(n):
    if n==0 or n==1:
    elif n==2:
        for x in range(2,n):
            if n%x!=0:


a function ends the moment a return keyword is reached, in your case this happens in the first run of the loop. You should check if the remainder equals zero, if it does return false

then place return True outside the for loop so the whole can run (only if the whole loop can run, the number actually is a prime)


return is not a function. When we wrap the value in parens we return a tuple. That may change things at the calling end.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.