Answer to Question #236400 in Python for Suraj

Question #236400

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
Expert's answer
2021-09-15T03:26:14-0400
def prime(n):
    f = False
    if n > 1:
        for i in range(2, n):
            if (n % i) == 0:
                f = True
                
            break
    return f






def inputNumbers(n):
    count = 1
    list1 = []
    print('Enter '+str(n) +' numbers: ')
    while True:
        if count <= n:
            d = int(input())
            list1.append(d)
        else:
            break
        count += 1
    return list1
    
n =int(input())
list2 = inputNumbers(n)
for i in list2:
    if prime(i) == False:
        print("The first prime number is:  "+str(i))
        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
New on Blog
APPROVED BY CLIENTS