I honestly don't really know what I'm doing. I don't really understand this exercise and the n and the x. Could someone help me?

def is_prime(x):
    x != 0
    for n in range(2,x-1):
        if x % n == 0:
            return False
            return True


This is an expression the yields a boolean; however, without an assignment or conditional, it is in a vacuum. Consider,

if x < 2: return False

That return should not be inside the loop.


Where do I put my return True statement?


At the very end of the function, just inside the code block.

The number 2 will get kicked out of the loop since it is not in the range. It will default to the final True that is returned. Any values that survive the loop, will fall down to that line, as well.


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