Dremendo Tag Line

Input 10 numbers in integer array and print only the prime numbers from it in Python

Arrays - Question 4

In this question, we will see how to input 10 numbers in integer array and print only the prime numbers from it in Python programming. To know more about arrays click on the arrays lesson.

Q4) Write a program in Python to input 10 numbers in integer array and print only the prime numbers from it.

A prime number is a number which is divisible by 1 and itself. Example: 13, 17, 19, etc.

Program

from array import *

a=array('i',[])

print('Enter 10 numbers')
for i in range(10):
    a.append(int(input()))

print('\nPrime Numbers')
for i in range(10):
    c=0
    for j in range(1,a[i]+1):
        if a[i]%j==0:
            c=c+1

    if c==2:
        print(a[i],end=' ')

Output

Enter 10 numbers
5
12
18
23
17
45
93
62
7
54

Prime Numbers
5 23 17 7
video-poster