Code for finding the 1000th prime

Carsten Haese carsten.haese at gmail.com
Tue Nov 17 15:33:34 CET 2009


Stefan Behnel wrote:
> Robert P. J. Day, 15.11.2009 15:44:
>> On Sun, 15 Nov 2009, mrholtsr wrote:
>>
>>> I am absolutely new to python and barely past beginner in programming.
>>> Also I am not a mathematician. Can some one give me pointers for
>>> finding the 1000th. prime for a course I am taking over the internet
>>> on Introduction to Computer Science and Programming. Thanks, Ray
>>   it's 7919.
> 
> Now, all that's left to do is write a prime number generator (a random
> number generator will do, too, but writing a good one isn't easy), run it
> repeatedly in a loop, and check if the returned number is 7919. Once it
> compares equal, you can print the result and you're done.

Just do a brute-force search:

for i in range(10000):
    if i==7919:
        # Found it!
        print i

;-)

--
Carsten Haese
http://informixdb.sourceforge.net




More information about the Python-list mailing list