Menu Close

Print the First N prime numbers.

Print the First N prime numbers in Python.

N=int(input('Enter the N number: '))
L=list()
for i in range(2,N):
    flag=0
    for j in range(2,N+2):
        if i!=j:
            if i%j==0:
                flag=1
                break
    if flag==0:
        L.append(i)
print(L)

If you want to find prime numbers between two range click here.

Input_1:
Enter the N number: 100
Output:
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]


Input_2:
Enter the N number: 200
Output:
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]

Morae Q!