Answer to Question #254494 in Python for sai

Question #254494

you are given N inputs. wirte a program to print first prime number in given inputs.


Input 1

5

1

10

4

3

2


input 2

4

2

3

5

7


1
Expert's answer
2021-10-21T05:21:18-0400
def is_prime(num):
    if num > 1:
        if num == 2:
            return True
        for i in range(2,num):
            if (num % i) == 0:
                return False
            else:
                return True
    
    else:
        return False
is_prime(2)

N = int(input('Enter number here: '))
list1 = []
for i in range(N):
    j = int(input('Enter integer here: '))
    list1.append(j)
for i in list1:
    if is_prime(i) == True:
        print(i)

Enter number here: 6
Enter integer here: 5
Enter integer here: 1
Enter integer here: 10
Enter integer here: 4
Enter integer here: 3
Enter integer here: 2
5
3
2

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS