Skip to content

How to check nth prime in Python?

def isprime(n):
    c=0
    for i in range(1,n+1):
        if(n%i==0):
            c=c+1
    if c==2:
        return 1
    else:
        return 0
n=int(input())
c=0
x=1
while(c<=n):
    x=x+1
    for i in range(2,x+1):
        if isprime(i):
            c+=1
print(x)   
See also  How to add list numbers in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.