Function keeps doing the same thing
<p>This program suppose to find 1000 prime numbers and pack them into a list</p>

<p>Here's the code:</p>

<pre><code>num = raw_input('enter a starting point')
primes = [2]
num = int(num)
def prime_count(num):

    if num % 2 == 0: #supposed to check if the number is divided by 2 evenly
        num = num +1 #if it is, then add 1 to that number and check again
        return num


    elif num % num == 0:
        primes.append(num) #supposed to add that prime to a list
        num = num + 1 #add 1 and check again
        return num


while len(primes) &lt;= 999:
    prime_count(num)
</code></pre>

<p>So what actually happens when I run it:
it asks me raw_input and then goes to various things depending on what I choose as input:</p>

<ul>
<li>If I choose a prime, let's say 3, it runs and adds 999 of 3s to the list instead of adding it just one time and going on to try 4</li>
<li>If I choose a non-prime, let's say 4, it just breaks, after that I can't even print out a list</li>
</ul>

<p>What am i doing wrong?</p>

<p>UPDATE:
I fixed it, but when i run it with this i'm getting an error (TypeError: unsupported operand type(s) for %: 'NoneType' and 'int')</p>

<pre><code>number = raw_input('enter a starting point')
primes = [2]
number = int(number)
def prime_count(x):

    if x % 2 == 0: #supposed to check if the number is divided by 2 evenly
        number = x +1 #if it is, then add 1 to that number and check again
        return number



    else:
        for i in range(3, x-1):
            if x % i == 0:
                primes.append(x) #supposed to add that prime to a list
                number = x + 1 #add 1 and check again
                return number


while len(primes) &lt;= 999:
    number = prime_count(number)
</code></pre>

<p>You're never using the return value from prime_count. Try this:</p>

<pre><code>while len(primes) &lt;= 999:
    num = prime_count(num)
</code></pre>

<p>You've set your self up for confusion by using the name  <code>num</code> as both a parameter  (also a local variable) inside of <code>prime_count</code>, and also as a global variable. Even though they have the same name, they are different variables, due to Python's rules for the scope of variables.</p>

<p>Also, <code>prime_count</code> is (probably unintentionally) leveraging the fact that <code>primes</code> is a global variable. Since you're not <em>assigning</em> to it, but rather just calling a method  (append), the code will work without using the <code>global</code> keyword.</p>

<p>However, your algorithm isn't even correct. <code>if num % num == 0</code> says <em>"if a number divided by itself has a remainder of zero"</em> which will <em>always</em> be true. This program will find a lot of "primes" that aren't primes.</p>

<p>Real Python programs do very little in the global scope; your current code is just asking for confusion.  I suggest you start with this template, and also do some reading of existing Python code.</p>

<pre><code>def add_three(a_param):
    a_local_var = 3       # This is *different* than the one in main!
                          # Changes to this variable will *not* affect
                          # identically-named variables in other functions

    return a_local_var + a_param

def main():
    a_local_var = 2

    result = add_three(a_local_var)

    print result    # prints 5

if __name__ == '__main__':
    main()
</code></pre>

python function loops