#!/usr/bin/python

P = [1, 2]

count = 1

def prime4WRT (P, a, l):
    global count
    iscomposite = False
    while (l <= count) and not(iscomposite):
        h = P[l]
        iscomposite = (h <= a // h) and (a % h == 0)
        l += 1
    return not(iscomposite)

def generate4From (P, m, n, k):
    global count
    while k <= n:
        # print ('Trying m = ', m)
        if prime4WRT (P, m, 1):
            P.append (m)
            # print P
            count = k
            k += 1
        else:
            pass
        m += 2

#def gen1000Primes():
#    generate4From (3, 1000, count+1)

def printArray (P):
    global count
    for i in range(1, count+1):
        print 'Prime [', i, '] = ', P[i]

#gen1000Primes ()
generate4From (P, 3, 1000, count+1)
printArray (P)
