Python Program to find prime numbers using a list


In this program, You will learn how to find prime numbers using a list in Python.


data = [2, 3, 4, 5, 6]

Example: How to find prime numbers using a list in Python

data = []
print("Enter how many number:", end="")
n = int(input())

print("Enter numbers:", end="")

for i in range(0, n):
    num = int(input())

    data.append(num)

print("Prime numbers are:", end=" ")

for i in range(0, n):
    num = data[i]
    j = 2
    f = 1
    while j < num:
        if num % j == 0:
            f = 0
            break
        j = j + 1

    if f == 1:
        print(data[i], end=" ")

Output:

Enter how many number:5
Enter numbers:2
3
4
5
6
Prime numbers are: 2 3 5