Determine if number is a prime number I made a function that takes an argument x and returns True if x is a prime number and False if x is a non-prime number.

I am a beginner and think the code can be improved. I had to add the else statement because for is_prime(2), I kept getting None instead of True. I think this was because when x is 2, list_n = range(2,2) prints []. 

Are there ways I could change this so there is not a separate else statement?

def is_prime(x):
    list_n = range(2,x)

    if x &lt;= 1:
        return False
    elif x-1&gt;2:
        for n in range(len(list_n)):
            list_n[n] = x % list_n[n]
        for n in list_n:
            if n == 0:
                return False
        for n in list_n:
            if n &gt; 0:
                return True
    else:
        return True
To begin with, you don't need list_n at all: a decision that the number is composite can be made on the fly, as soon as some remainder becomes 0. If none of them were 0, you know that the number is prime:

    for n in range(2, x):
        if x % n == 0:
            return False
    return True


is effectively what your code is doing, but without the list, and without special case for 2.

That said, of course the algorithm could be greatly improved, but it is beyond the point of this exercise.