title: Python List (with prime numbers)
body: <p>I am a beginner at Python, and I need help fixing this piece of code i have created.  Bassicaly, I have my code here below.  </p>
  
  <pre><code>import math
  
  def generate_p(p, Count, X, List):
      while Count &lt;= X:
          isprime = True
          for x in range(2, int(math.sqrt(p)) + 1):
              if p % x == 0:
                  isprime = False
          if isprime:
              Count += 1
              print p
              P.append(p)
          p += 1
  
  if __name__ == "__main__":
      p = 2
      count = 1
      X = int(raw_input('number: '))
      List = []
      generate_p(p, count, X, List)
  </code></pre>
  
  <p>Basically, The function does work, however, it does not function how i want it to function.  First, i will say how the function's logic work, since the second part of the code is just variables and declaring the function.<br>
  while the variable count is less or equal to X, is prime is true, as long as p (the number being tested) can go into every x without a remainder (x is in a range of 2 through the square root of p).  If it is prime, add 1 to the count, print the prime, add it too the list, and then and 1 to p, the number being tested.  If it is not prime, then just add 1 to p.  This keeps going until Count is greater than X, then the code stops.<br>
  As you have probably noticed by now, there is a list collecting prime numbers, however, this is mostly being unused.  What i want to do, but I don't know how to do, is fix this part of the code, </p>
  
  <pre><code>for x in range(2, int(math.sqrt(p)) + 1):
      if p % x == 0:
          isprime = False
  </code></pre>
  
  <p>so that x is in the range of 2 and the square root of p+1, however, i only want x to be numbers in that range that are in the list of P.  Can anyone help me do this, and maybe point out any other things in this code?  </p>