Answer to Question #345160 in Python for Skvp

Question #345160

You are given n inputs, write a program to print the first prime number in the given inputs.


In the given example of 5 integers.

5

1

10

4

3

2


Output should be

3


1
Expert's answer
2022-05-26T09:14:31-0400
num = []
while True:
    c = input('Please, input how many integers you want to check => ').strip()
    if c.isdigit():
        c = int(c)
        break
    else:
        print('You should input integer number')
print()
while len(num) != c:
    n = input('Please, input any number => ').strip()
    if n.isdigit():
        num.append(int(n))
    else:
        print('You should input number!')
result = 'Any of your number are not prime'
for n in num:
    if n != 1:
        counter = 0
        for i in range(1, n+1):
            if n % i == 0:
                counter += 1
            if counter > 2:
                break
        if counter == 2:
            result = str(n)
            break
if result.isdigit():
    print(result)
else:
    print(result)

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