[ create a new paste ] login | about

Link: http://codepad.org/G52Va8xf    [ raw code | output | fork ]

Python, pasted on Feb 10:
primes = [2,3]
##start off the list of 2 primes

numprime = int(raw_input ('Enter number of primes:'))
##input no. of primes we want to find

num =  primes[-1]+2
##locate the first odd number to test as prime


##we continue the 'while loop' till we reach the target number of primes   
while (len(primes) < numprime):

    isthisprime = True
    ##test whether new odd number is a prime by fidning module agaisnt all other primes
    for prime in primes:
##        print ("current number is ") + str(num) + (" and currlen is: ") + str(currlen)
        if num % prime == 0:
            isthisprime = False
            break
            
    if isthisprime:
        primes.append(num)
    num = num +  2  

print primes


Output:
1
2
3
4
Enter number of primes:Traceback (most recent call last):
  Line 5, in <module>
    numprime = int(raw_input ('Enter number of primes:'))
EOFError


Create a new paste based on this one


Comments: