Answer to Question #227336 in Python for srikanth

Question #227336
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-20T14:17:22-0400
def number_of_digits():
    number = int(input('Enter number of digits: '))
    return number


def entering_numbers(number):
    counter = 1
    numbers = []
    while True:
        if counter <= number:
            digit = int(input('Enter sequence number: '))
            numbers.append(digit)
        else:
            break
        counter += 1
    return numbers


def find_prime(subsequence):
    i, j, flag = 0, 0, 0
    for i in subsequence:
        if (i == 1 or i == 0):
            continue
        flag = 1
        for j in range(2, ((i // 2) + 1), 1):
            if (i % j == 0):
                flag = 0
        if (flag == 1):
            print('First prime: ', i)
            break
            
def main():
    number = number_of_digits()
    subsequence = entering_numbers(number)
    find_prime(subsequence)
    
if __name__ == "__main__":
    main()

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