Answer to Question #236714 in Python for mahesh

Question #236714

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.


1
Expert's answer
2021-09-13T18:30:26-0400
def is_prime(x):
    i = 2
    while i <= int(x ** 0.5):
        if x % i == 0:
            return False
        i += 1
    return True


n = int(input('N='))
primes = []
for i in range(n):
    x = int(input())
    if is_prime(x) and x != 1:
        primes.append(x)
if len(primes) > 0:
    print('the first prime number= ', primes[0])
else:
    print('There are no prime numbers')

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