Blogger Tips and TricksLatest Tips And TricksBlogger Tricks

Program to Find n prime Number in python


" Program to Find n prime Number"
print ("Program to Find n prime Numbers")

def prime(n):
    ls = [2,3]
    if (n < 3):
        return ls[:n]
    for i in range(2,n):
        temp = ls[-1]+2
        while any(not(temp%num) for num in ls):
            temp += 2
        ls.append(temp)
    return ls

n = int(input("Enter the  N value :"))
print ("The ", n ,"prime numbers are")
print (prime(n))

No comments:

Post a Comment

Flag Counter