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
def isprime(n):
s = []
if n == 2:
return True
elif n % 2 == 0:
return False
elif n == 1:
return False
elif n % 2 != 0:
if n == 3:
return True
elif n > 3:
for i in range(3,n):
if n % i == 0:
s.append(n)
if len(s) >= 1:
return False
elif len(s) == 0:
return True
list1 = []
N = int(input('Enter integer here: '))
for i in range(N):
n1 = int(input('Enter numbers here: '))
list1.append(n1)
for i in list1:
if isprime(i) == True:
print(i)
break
Enter integer here: 5
Enter numbers here: 1
Enter numbers here: 10
Enter numbers here: 4
Enter numbers here: 3
Enter numbers here: 2
3
Comments
Leave a comment