Answer to Question #226584 in Python for kaavya

Question #226584

First Prime Number

You are given N inputs. Write a program to print the first prime number in the given inputs.

Input

The first line of input is an integer N. The next N lines each contain an integer. Explanation

In the given example of

5 integers

1

10

4

3

2


The output should be

3.

Sample Input 1

5

1

10

4

3

2

Sample Output 1

3

Sample Input 2

4

2

3

5

7

Sample Output 2

2




1
Expert's answer
2021-08-17T16:54:22-0400
n = int(input("Enter a positive integer: "))


is_primes = []  # list of potential prime numbers(contains primes and non primes)


for count in range(n):
    read = int(input("> "))
    is_primes.append(read)


non_primes = []


for num in is_primes:


    if num == 2 or num == 3:
        pass
    else:
        for i in range(2, num):
            if num % i == 0:
                non_primes.append(num)
                break
            else:
                pass


            
print(sum(non_primes))


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