Okay, let's clear this up once and for all!
You are using range (2,x-1) instead of (2,x). In the original code you have posted this was correct
How does range work? Range starts with the number you specify but it does not end with the second number. To illustrate, range(2,5) starts at 2 goes to 3 and finally 4. Therefore, you should not use x-1.
You can think of range as (starts at, stop one before this number).
Secondly, you left the indentation same for the else: statement (as in the original code you posted).
Thus, the code should look like this:
If it helps, the else: does not even need to be there as here (notice the indentation!):
Hopefully this helps