title: Generating a list of prime numbers. - beginner
body: <p>I am just starting out, and I've written the following code and have been trying to debug it for a few hours.  I am not getting something very basic here.  I want the code to give me a list of prime numbers up to length specified in the call parameter. I started out with a list of the first four, just to get things going and make coding easier.  The basic algorithm I want to use is to add two to the last member of the list, then check whether the last number in the list is prime by determining whether the other members of the list divide it, starting with the first member.  I'd like to stop checking at the point when the value of the divisor exceeds the square root of the candidate prime, but I haven't figured out how to even attempt that.</p>
  
  <p>I am getting an error in line 5, which I can't understand, but I'm sure there are other problems with the code as well.</p>
  
  <pre><code>def prime_list(length):
      L = [2, 3, 5, 7]
      j = 9
  
      while length &gt; len(L):
          prime = True
          i = 0
          for divisor in L:
              while divisor in range (0, len(L) - 2) and prime == True:
                  if j % divisor == 0:
                      prime = False
          if prime == False:
              j = j + 2
          else:
              L = L.append(j)
      return L
  </code></pre>