title: Does anyone know why my program doesn't generate the correct amount of prime numbers?
body: <pre><code>print(&quot;Number of primes must be greater than 2&quot;)
  number = int(input(&quot;Number of primes: &quot;))
  if number &lt; 1:
      print(&quot;Invalid input&quot;)
      exit()
  print(2)
  print(3)
  i = 0
  no_primes = 2
  while 1 &lt; 2:
      m = 6 * i - 1
      n = 6 * i + 1
      if (2 ** m) % m == 2:
          print(m)
          no_primes += 1
      if no_primes == number:
          break
      if (2 ** n) % n == 2:
          print(n)
          no_primes += 1
      if no_primes == number:
          break
      i += 1
  </code></pre>
  <p>My code uses the fact that primes can be expressed in the form 6n-1 or 6n+1 except for 2 and 3. My while loop looks quite strange but I don't have the expertise to manoeuvre with loops consisting of two variables (no_primes and i in this case). When I generate the first 1000 primes, it skips a few, ending with 7789 instead of 7919. Does anybody know why? Also, sorry if the code looks redundant. If it is, please do state how I can improve it</p>
  <p>I started python only a few weeks ago, thought you'll should know</p>