Answer to Question #226152 in Python for GANESH

Question #226152

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


1
Expert's answer
2021-08-18T06:51:19-0400
def isPrime(n):
    if n % 2 == 0:
        return n == 2
    d = 3
    while d * d <= n and n % d != 0:
        d += 2
    return d * d > n

N = int(input())
t = []
for _ in range(N):
	t.append(int(input()))
for num in t:
	if isPrime(num):
		print(num)
		break

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
APPROVED BY CLIENTS