### Fork prime repository in GitHub

#7919 - 1000th prime #541 - 100th prime ## program to find any prime i=0 pcnt=0 while(1): i=i+1 cnt=0 for j in range(1,i+1): if i%j==0: cnt=cnt+1 else: continue if cnt==2: pcnt=pcnt+1 if pcnt==1000: print pcnt,'th prime is',i break

Note: This algorithm is not an efficient one. Change the 1000 to your desired number.

Optimized one is at: https://unreachable2027.wordpress.com/2012/10/02/python-script-to-find-nth-prime-optimized/

Advertisements

Just a tip: You can use the ‘sourcecode’ tag to display Python code. It will preserve indentation and give you syntax highlighting too.

You can find out more at Posting Source Code.

Here’s an example (you have to add an opening bracket to make it work)…

sourcecode language=”Python”]

hello = “world”

[/sourcecode]

Thank you for the tip. I updated.

for an optimized program

check here:

https://unreachable2027.wordpress.com/2012/10/02/python-script-to-find-nth-prime-optimized/